我在python中编程。我试图让用户猜测1到100之间的数字。我确定我有正确的代码,但我一直在语法错误,而#39;
import random
def guessthenumber():
print("Welcome user. In this game, you must correctly guess a randomly generated number between 1 and 100.")
guessamount = 1
randomnumber = random.randrange(1, 100)
numberguess = int(input("Please enter your guess")
while numberguess != numbertoguess:
if numberguess < numbertoguess:
print("You must guess higher.")
elif numberguess > numbertoguess:
print("You must guess lower.")
guessamount += 1
print("You have correctly guessed the number! It took you {} guesses".format(guessamount))
屏幕截图:
答案 0 :(得分:0)
你只是缺少一个括号:
numberguess = int(input("Please enter your guess"))
答案 1 :(得分:0)
numberguess = int(输入(“请输入您的猜测”)
你错过了a)最后关闭int()部分...