lwrnmbr = 0.0
hghrnmbr = 100.0
a = 1
while (a == 1):
guess = (lwrnmbr + hghrnmbr) / 2
guessword = str (guess)
answr = (input("are you thinking of "+ guessword + "? type 'h' if that's too high, type 'l' if it's too low, and type 'r' if it's right"))
if(answr == "h"):
hghrnmbr = answr
elif(answr == "l"):
lwrnmbr = answr
elif(answr == "r"):
print("thanks for playing")
break
答案 0 :(得分:0)
您不正确地将hghrnmbr / lwrnmbr重新分配为等于您收到的输入,这是我希望您希望将其设置为您所做的猜测的结果。另外,在对数字进行数字运算之前,请确保将guessword
转换为整数。
while (a == 1):
guess = (lwrnmbr + hghrnmbr) / 2
guessword = str (guess)
answr = (input("are you thinking of "+ guessword + "? type 'h' if that's too high, type 'l' if it's too low, and type 'r' if it's right"))
if(answr == "h"):
hghrnmbr = int(guessword)
elif(answr == "l"):
lwrnmbr = int(guessword)
elif(answr == "r"):
print("thanks for playing")
break