数字猜谜游戏Python
我想写一个从用户那里得到的数字猜测游戏。即使答案正确,循环也不会结束。我该怎么办数字猜谜游戏Python,python,math,Python,Math,我想写一个从用户那里得到的数字猜测游戏。即使答案正确,循环也不会结束。我该怎么办 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("
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
number=int(输入(“输入一个介于1和100之间的数字:”)
猜测=50
n=1
如果数量>100:
number=int(输入(“输入一个小于100的数字:”)
如果数字您应该将从末尾移动到如果ans==“b”:
…如果ans==“g”:
和如果ans==“l”:
块(无需打印两次问题)并将guess*0.5
替换为guess//2
,以避免分数。