我很难完成这个猜数字作业。我似乎无法正确处理并需要一些帮助。再次游戏选项不起作用,因为当您赢得游戏并选择“是”再次游戏时,它不会重新开始游戏,它会继续您的下一个猜数(例如:猜数 1、猜数 2...)。但是当你输了它会回到第一部分,它会问你“你想要多少次尝试”。那么我怎样才能获得你获胜的部分呢?另外,有人可以给我一些关于如何改进提示选项的提示吗?另外,我是否需要插入任何def main():东西?因为我不确定我们是否已经完成了这项任务。所以请帮帮我。谢谢。
# This is a guess the number game.
import random
answer = "yes"
number = random.randint(1, 10)
while answer == 'yes':
tries = 0
guess = 0
guessnumber = 0
tries = int(input("How many tries would you like? "))
tries2 = tries
while guessnumber != tries2:
guessnumber += 1
guess = int(input("Enter guess number " + str(guessnumber) + ": "))
if guess < number:
print("You guessed too low")
hint = input("Would you like a hint, yes or no?: ")
if hint == "no":
continue
print("The number is less than", number + 1)
if guess > number:
print("You guessed too high")
hint = input("Would you like a hint, yes or no?: ")
if hint == "no":
continue
print("The number is greater than", number - 1)
if guess == number:
tries = str(tries)
print("YOU WON!")
answer = input("Play again? Yes/No? ") `enter code here`
if answer == 'no':
break
if guess != number:
number = str(number)
print("GAME OVER!!! The number I was thinking of was " + number)
answer = input("Play again? Yes/No? ")
if answer == "no":
break