Python 重复菜单,但只重复一次

Python 重复菜单,但只重复一次,python,Python,每当我选择选项1玩游戏时,菜单会自动重置并从头开始。它只会这样做一次,但在第二次,选择选项1开始游戏。 当我选择任何其他选项时,它会在第一次尝试时运行,不会重复。有什么可以阻止这一切的吗 #Jake Eaton #Menu import time from typing import type, type2 from main_game import Main_Game #Imports t

每当我选择选项1玩游戏时,菜单会自动重置并从头开始。它只会这样做一次,但在第二次,选择选项1开始游戏。 当我选择任何其他选项时,它会在第一次尝试时运行,不会重复。有什么可以阻止这一切的吗

#Jake Eaton
#Menu

import time
from typing import type, type2
from main_game import Main_Game                                                     #Imports time, system and name Modules
from view_leaderboard import View_LB                                                #Imports defined code with the names type, type 2, Main_Game and View_LB
from os import system, name

def clear():
    if name =='nt':                                                                 #Defines the clear command for the Terminal
        _ = system('cls')

type("Welcome\n")
time.sleep(2)
type("Welcome to the only Text Adventure you will ever need to play in order to learn!\n")
time.sleep(2)
type("This Text Adventure covers the AQA A-level Computer Science Topic 4.6\n")
time.sleep(2)
type("Please remember that this is still in Beta and may never have a full 1.0 release\n")
time.sleep(2)
type("All releases and the source code can be found on Github using the link: https://github.com/Spud-Lord/Mock-NEA\n")
time.sleep(2)
type("To view the releases, just click on the releases tab on the Github Page\n")
time.sleep(2)
type("So let us begin!")
time.sleep(2)


type("Now then...")
time.sleep(2)
type("What do you want to do? Just type in the number of the option you want!")
time.sleep(2)
def Main_Menu():                                                                    #Defines all indented code as Main_Menu
    menu = input("""
[1] - Start Game!
[2] - View Leaderboard  
[3] - Exit Game

""")                                                                                #The triple speech marks allow the Menu to go over multiple lines with only one code

    if menu == "1":
        clear()                                                                     #Calls Clear Definition to clear Terminal Screen
        Main_Game()

    elif menu == "2":
        print("")
        View_LB()                                                                   #Calls View_LB Definition to view leaderboard
        time.sleep(2)
        print("")
        Main_Menu()

    elif menu == "3":
        exit()                                                                      #Exits the game

    else:
        type("Please type in one of the numbers above...\n")
        Main_Menu()                                                                 #Loops back round if the user doesn't enter one of the numbers
        
Main_Menu()                                                                         #Allows the Menu to loop

我没有用以下代码重现您的问题。 看来您至少需要将
类型(…)
替换为
打印

需要清理代码,使其更具可读性。首先放置所有函数,然后添加代码的主要部分(从打印(“欢迎\n”)开始)


在调用
Main\u Game()
之后,再次尝试调用
Main\u Menu()
——就像你在
的所有其他分支中所做的那样,如果
。不,那不起作用。不幸的是,那不起作用。我用我想让它实际做的东西代替了指纹,但它不起作用。当指纹还在的时候,它确实起作用了!但是我想让它实际运行函数中的代码,这个函数在一个单独的程序中
#Jake Eaton
#Menu

import time

#from main_game import Main_Game                                                     #Imports time, system and name Modules
#from view_leaderboard import View_LB                                                #Imports defined code with the names print, print 2, Main_Game and View_LB
from os import system, name

def clear():
    if name =='nt':                                                                 #Defines the clear command for the Terminal
        _ = system('cls')

print("Welcome\n")
time.sleep(2)
print("Welcome to the only Text Adventure you will ever need to play in order to learn!\n")
time.sleep(2)
print("This Text Adventure covers the AQA A-level Computer Science Topic 4.6\n")
time.sleep(2)
print("Please remember that this is still in Beta and may never have a full 1.0 release\n")
time.sleep(2)
print("All releases and the source code can be found on Github using the link: https://github.com/Spud-Lord/Mock-NEA\n")
time.sleep(2)
print("To view the releases, just click on the releases tab on the Github Page\n")
time.sleep(2)
print("So let us begin!")
time.sleep(2)


print("Now then...")
time.sleep(2)
print("What do you want to do? Just print in the number of the option you want!")
time.sleep(2)
def Main_Game():
    print ("Main game")

def View_LB():
    print ("LB")

    
def Main_Menu():                                                                    #Defines all indented code as Main_Menu
    menu = input("""
[1] - Start Game!
[2] - View Leaderboard  
[3] - Exit Game

""")                                                                                #The triple speech marks allow the Menu to go over multiple lines with only one code

    if menu == "1":
        clear()                                                                     #Calls Clear Definition to clear Terminal Screen
        Main_Game()

    elif menu == "2":
        print("")
        View_LB()                                                                   #Calls View_LB Definition to view leaderboard
        time.sleep(2)
        print("")
        Main_Menu()

    elif menu == "3":
        exit()                                                                      #Exits the game

    else:
        print("Please print in one of the numbers above...\n")
        Main_Menu()                                                                 #Loops back round if the user doesn't enter one of the numbers
        
Main_Menu()