python 2.7怎么编辑猜数字
发布网友
发布时间:2022-05-24 19:33
我来回答
共1个回答
热心网友
时间:2023-10-28 00:42
给你些关键提示吧
剩余猜测次数:remaining = int(math.ceil(math.log(num_range,2))) num_range为数值范围,比如100。
猜测判断:剩余次数为0游戏结束,否则减一次剩余猜测次数,并提示数值大于/小于猜测值,或是猜测正确。
global remaining
if remaining <= 0 :
print "\nNo more guess chances remaining.\nStarting a new game!"
new_game()
else:
guess = int(guess)
print "\nGuess was", guess
remaining -= 1
print "Number of remaining guesses is", remaining
if guess == number:
print "Correct!"
new_game()
elif number > guess:
print "Higher!"
else:
print "Lower!"