选择是后如何使程序重新运行?

时间:2019-07-10 07:21:37

标签: python

我正在尝试让程序运行,直到用户不会键入“否”为止。这是我已经完成的代码:

[hook "startcommit"]
    cmdline = %root%\\ARM\\start_commit.bat
    wait = true
    show = false
[hook "postcommit"]
    cmdline = %root%\\ARM\\start_commit.bat
    wait = true
    show = false
[hook "precommit"]
    cmdline = %root%\\ARM\\start_commit.bat
    wait = true
    show = false

2 个答案:

答案 0 :(得分:0)

您应该首先导入sys库,然后将其余代码放入While True循环中。在代码末尾写:

Answer = input ("Do you want to continue? (y/n)")
If Answer == 'n' :
    sys.exit

请注意,上面的代码是while true循环中的最后一件事

答案 1 :(得分:0)

english= "Hello iso-3166-2: en-us"
french= "Salut! iso-3166-2:fr"
spanish= "Ola iso-3166-2:es"

print("What language would you prefer?\n e for English, s for spanish, f for french")

choice = input("Your choice\n")

while True:
    if choice == "e":
        print(english)
    elif choice == "f":
        print(french)
    elif choice == "s":
        print(spanish)
    res = input("Do you want to choose another language? Yes/No:")
    if res == 'Yes':
        print("What language would you prefer?\n e for English, s for spanish, f for french")
        choice = input("Your choice\n")
    elif res == 'No':
        print ("Goodbye")
        break

输出:

What language would you prefer?
 e for English, s for spanish, f for french
Your choice
e
Hello iso-3166-2: en-us
Do you want to choose another language? Yes/No:Yes
What language would you prefer?
 e for English, s for spanish, f for french
Your choice
f
Salut! iso-3166-2:fr
Do you want to choose another language? Yes/No:No
Goodbye