如何根据用户输入重置程序

时间:2018-04-18 01:12:51

标签: python-2.7

这是一个猜谜游戏,在代码的最后我想询问他们是否想再次玩游戏。如果他们确实说是,那么它从顶部开始,如果他们说没有程序结束。这就是我目前还不确定我做错了什么,我得到了一些帮助,这就是我到目前为止所拥有的

$('#2, #3').addClass("hidden");

1 个答案:

答案 0 :(得分:0)

您可以将游戏封装到一个功能中。然后,在函数调用周围使用循环:

name = input('Entrez votre nom: ')

def play(name):
    randomNumber = random.randrange(0,100)
    guesses = False
    # etc...


want_to_play = True

while want_to_play:

    play(name)  # This start your game

    want_to_play = input('Veux tu encore jouer? (O/N)')
    if want_to_play.lower() == 'o':
        want_to_play = True
    elif want_to_play.lower() == 'n':
        want_to_play = False # EDIT: oups, thanks Primusa
    else:
        print('invalid input!')
        want_to_play = False
相关问题