作为我大学课程的一部分,我正在学习python,我一直在尝试(重新)编写这个猜测数字游戏,如果用户在5次尝试中未能正确猜中,将终止游戏:# Guess My Number Mod 5 tries or bust
import random
print("\nI'm thinking of a number between 1 and 100.")
print("Try to guess it in five tries or less")
my_number = random.randint(1, 100)
guess = int(input("Go on, Take a guess, I dare ya "))
tries = 1
while guess != my_number:
if guess > my_number:
print("Lower...")
else:
print("Higher...")
guess = int(input("Go on, Take a guess, I dare ya "))
tries += 1
if tries==5:
input("You failed to guess the number was it that hard?\n Press any key to exit!)"
print("Well done you guessed correctly!The number was", my_number)
print("And it only took you", tries, "tries!\n")
input("\n\nPress the enter key to exit.")
我假设终止原因不起作用,因为if语句在while循环之外,我无法使其生效。在
还有一些无效的语法,因为我累了,找不到它。在
如果可能的话,你们能给我一些提示,告诉我如何解决我想做的事情,因为我更有可能学会这样做。在