首先,我感谢您提供的任何答案。
无论如何,我是 Python 和一般编程的初学者。我尝试创建自己的随机数猜测游戏,计算机在 1-15 之间选择一个随机数,yada yada。
我的问题是,当我试图告诉用户他们的猜测是太低还是太高时,程序要么终止,而不会通知用户它们是否正确。或者它只是不断循环。
太低了,请再猜:14
正确的!你猜到我的号码了!
太低了,请再猜:12
太低了,请再猜一猜:1
太低了,请再猜一猜:
这是我这个程序的全部代码:
import random
from time import sleep
number = random.randint(1,15)
play = input("Hello! Would you like to play (Y/N) ")
if play in('y', 'Y'):
sleep(.75)
print("I've chosen a number between 1 and 15.")
sleep(.5)
guess = int(input("What is my number? "))
while guess >= number:
guess = int(input("Too High, please guess again: "))
if guess == number:
print("Correct! You've guessed my number!")
while guess <= number:
guess = int(input("Too Low, please guess again: "))
if guess == number:
print("Correct! You've guessed my number!")
else:
exit
再次感谢您的任何回答!