import random
random_number = random.randint(1,10) #numbers 1 - 10
guess = None
while True:
guess = input("pick a number from 1 to 10 \n")
guess = int(guess)
if guess < random_number:
print("Too low")
elif guess > 10:
print("pick a number from 1 to 10")
elif guess > random_number:
print("It's high")
else:
print("You won")
play_again = input("Do you want to play again? (y/n) ")
if play_again == "y":
random_number = random.randint(1,10) #numbers 1 - 10
guess = None
else:
print("Thank you for playing!")
break
答案 0 :(得分:0)
因为您打印了“从1到10选取一个数字”,然后在第8行的输入标签之后。
答案 1 :(得分:0)
如果您输入大于10的数字,它应至少打印3次
guess = input("pick a number from 1 to 10 \n")
elif guess > 10:
print("pick a number from 1 to 10")
然后循环重复
不清楚为什么在if-else中将10硬编码。相反,您可以尝试继续循环
while True:
guess = input("pick a number from 1 to 10 \n")
guess = int(guess)
if guess > 10:
continue