是否有命令将代码重置为某一行((Python)

2024-05-15 18:00:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我几乎完成了我一直在做的一个项目,这是一个刽子手游戏。我一直在尝试添加一个功能,您可以在完成后重新启动游戏,并选择一个新的难度。这是可行的,但只要你选择了一个已经被选择的难度,它就会终止程序。我想知道是否有一个命令允许我将程序重置到代码开头的某一行

Full Code Here

问题区域B(供参考):

  if lives == 0:
    print("           ")
    print("-Im sorry, " + playername + ", it seems that you cannot make any more mistakes.")
    print("-The answer was '" + letter1 + letter2 + letter3 + letter4 + "'.")
    print("-Better luck next time.")
    print("                           ")
    playagain = str(input("Would you like to play again, " + playername + "? "))
    while True:
        if playagain in (accept, reject):
            break
        print("                           ")
        print("-I'm sorry, " + playername + ", I do not understand your answer . . .")
        print("                           ")
        playagain = str(input("Would you like to play again, " + playername + "? "))
        print("                           ")

    if playagain == accept:
         lives = 6
         from random import randint
         num = randint(1,10)
         true1 = False
         true2 = False
         true3 = False
         true4 = False
         difficulty = str(input("Choose a difficulty, easy, medium or hard. "))
         break

    if playagain == reject:
         print("⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀")
         print("Thank you for playing!")
         print("This game was coded by *developer name*")
         break

Tags: answer程序youfalse游戏inputifprint