以下是代码:
import random
secretNumber = random.randit(1, 20)
print("I'm thinking of a nummber between 1 and 20.")
for guessesTaken in range(1, 7):
print("Take a guess.")
guess = int(input())
if guess < secretNumber:
print("Your guess is to low")
elif guess > secretNumber:
print("Your guess is to high")
else:
break # This condition is the correct guess!
if guess == secretNumber:
print("Good job! You guessed my number in " + str(guessesTaken) + "guesses!" )
else:
print("Nope.The number I was thinking of was " + str(secretNumber))
这是问题所在:
"AttributeError: module 'random' has no attribute 'randit'"
我尝试从“test.py”更改文件的名称,这是该文件的第一个名称,然后在“guessTheNumber.py”中,但仍然无效。
答案 0 :(得分:0)
拼写错误。也许你想要的是:
secretNumber = random.randint(1, 20)
它应该是randint(1,20)
而不是randit(1,20)