各位!! 所以,我试着编写一个简单的猜测游戏,但我一直得到相同的错误“名称‘上限’未定义”,并且不知道如何修复它。我会附上一个错误的截图以及
import math
lowerNum = int(input("Enter lower point: "))
upperNum = int(input("Enter upper point: "))
guesses = round(math.log(upperBound))
print("Number of guesses: ", guesses)
response = ""
count = 0
while response != "y" and count < guesses:
compGuess = round((lowerBound + upperBound)/2)
print ("Is your number: ", compGuess)
count += 1
response = input("either h if too high, l if too low, y if it's correct: ")
if response == 'h':
upperBound = compGuess
elif response == 'l':
lowerBound = compGuess
elif response == 'y':
print ("The computer guessed your answer in", count, "guesses.")
else:
print ("Invalid input" , end= '--')
count -= 1
compGuess = round((lowerBound + upperBound) /2)
if guesses <= 0:
print("Computer has used up all the guesses : (")
else:
pass
第3行定义:
然而第6行使用了
upperBound
:相关问题 更多 >
编程相关推荐