print("Please think of a number between 0 and 100!")
low = 0
high = 100
ans = (low + high)/2
while True:
print("Is your secret number %d " %ans)
userguess = input("Enter 'h' to indicate the guess is too high. Enter
'l' to indicate the guess is too low. Enter 'c' to indicate I guessed
correctly. ")
if userguess == 'h':
high = ans
elif userguess == 'l':
low = ans
elif userguess == 'c':
break
else :
print("Sorry, I did not understand your input.")
continue
ans = (low + high)/2
print("Game over. Your secret number was: %d" %ans)
當數字是42和91時,它不會按照它應該的方式工作。這段代碼有什麼問題。我的程序是關於猜測蟒蛇中0到100之間的數字
究竟什麼不行?它怎麼錯了? – poke
使用'/ /'而不是'/' – khelwood