我正在尝试制作一个数字猜谜游戏,当你猜对数字时,它会告诉你猜了多少次。
我已经尝试了几个循环,但无法弄清楚如何让我的“猜测”增加。
import random
rand_num = random.randrange(1,201)
def guess_game():
guess = int(input("Please enter your guess: "))
guesses = 1
if guess == rand_num:
print("Hit!\nIt took you " + str(guesses) + " guesses!")
elif guess < rand_num:
print("Your guess is too low.")
guesses = guesses + 1
guess_game()
else:
print("Your guess is too high")
guesses = guesses + 1
guess_game()
guess_game()
例如,所需的输出应该是这样的:
"Hit! It took you 5 guesses"
但无论尝试了多少次,它都只说 1 次猜测。
大话西游666
Qyouu
函数式编程
相关分类