从我的“ main_menu”功能获取输入,并使用它来启动“ play_game”功能

时间:2019-05-21 15:57:24

标签: python function

我是Python的初学者,大约只有一个星期!我正在开始我的第一个单独项目,在这个项目中,除非需要,否则我将尽量避免观看或复制他人的代码。无论如何,我想做一个小游戏,在其中提出有关场景的问题,用户可以选择场景。我计划尝试定义一些函数,以获得看上去“不太新手”的程序。我做了主菜单功能,我想从主菜单中获取用户输入,并使用它来开始游戏的实际玩法。

我几乎只求助于取消主菜单,然后将整个游戏整合到一个功能中。但是我真的很想学习正确使用函数和结构,而不是仅仅在一个主要功能下键入所有内容,甚至不定义函数。

def main_menu():

    print("----Hello Welcome To The Path----")
    startchoice = input('Would you like to (P)lay? or '
                        'do you want to (R)ead the instructions: ')
    if startchoice.upper() == "P":
        #Maybe return something here and use it to start function play_game()

    if startchoice.upper() == 'H':

        print('The game is simple!\nI will print out questions with' 
              '2 scenarios! and you pick one!')

        input('\n----Hit Enter to return to the main menu: ----')

        if input:
            main_menu()


def play_game():
#questions and scenarios will display here

我希望用户键入P进行游戏,然后开始游戏。在利用最有效的方法的同时,这将教会我将来编写合法应用程序/代码的良好习惯。

0 个答案:

没有答案