我想写一个猜用户的数字猜游戏号码。即使给出正确的答案,循环也不会结束。我该怎么办?
number=int(input("Enter a number between 1 and 100: "))
guess=50
n=1
if number>100:
number=int(input("Enter a number less than 100: "))
if number<1:
number=int(input("Enter a number greater than 1: "))
while True:
print("Your number is" +' '+ str(guess) +' '+ "?")
ans=str(input("(g)reater,(l)ess or (b)ravo: "))
for n in range(1,10):
if ans=="g":
guess=guess+guess//(2^n)
elif ans=="l":
guess=guess-guess//(2^n)
elif ans=="b":
print("Your number is " +' '+ str(guess) +' '+ "Well done for me")
break
答案 0 :(得分:0)
您应将break
从末端移到if ans=="b":