我在这里有一个更大的程序的一部分:
from random import randint
def computerChooses():
import random
choices = ["rock", "paper", "scissors"]
computerChoice = choices[randint(0,2)]
def whoWins():
if computerChoice == "rock":
print("DO THIS")
elif computerChoice == "paper":
print("DO THIS")
elif computerChoice == "scissors":
print("DO THIS")
computerChooses()
whoWins()
我总是以:
NameError: name 'computerChoice' is not defined
(即使我相信是这样!)
错误消息指出,这是针对第20行和第12行的。
我在哪里做错了,特别是在哪里?
谢谢, hy
答案 0 :(得分:-1)
from random import randint
def computerChooses():
import random
choices = ["rock", "paper", "scissors"]
computerChoice = choices[randint(0,2)]
return computerChoice
def whoWins(computerChoice):
if computerChoice == "rock":
print("DO THIS")
elif computerChoice == "paper":
print("DO THIS")
elif computerChoice == "scissors":
print("DO THIS")
result = computerChooses()
whoWins(result)