为我的学校工作添加一个循环

时间:2018-02-28 20:45:59

标签: python

我目前需要帮助添加一个重启程序的循环,在它询问用户是否想要添加另一个团队而不是让程序刚刚结束之后。

if rank == "expert": #If the user's rank is expert the programme will add an additional cost of 25 to the fee.
    if country == "EU": 
        print("Your fee is" + str(1.25*25*4)+"EUR")
    elif country == "US": 
        print("Your fee is" + str(1.50*25*4)+"USD")
    elif country == "AU":
        print("Your fee is" + str(2.00*25*4)+"AUD")
    else:
        print("Your fee is " + str(25*4)+"GBP")
else: #If the user's rank is anything other than expert such as beginner, the programme will charge the normal amount for the fee.
    if country == "EU":
        print("Your fee is" + str(1.25*10*4)+"EUR")
    elif country == "US": 
        print("Your fee is " + str(1.50*10*4)+"USD")
    elif country == "AU":
        print("Your fee is " + str(2.00*10*4)+"AUD")
    else:
        print("Your fee is " + str(10*4)+"GBP")

print("The names of your players are " +player1,player2,player3,player4)

print("Would you like to enter another team?") #Asks user if they would like to input another team.
answer = input() #Leaves a gap for the user to input.
answer = answer.lower() #Converts 'answer' into all lower case.
if answer == "yes": #Starts an 'if' statemant
    print("OK") #Displays 'OK' which tells the user the programme will continue.
else:
    print("Goodbye")

2 个答案:

答案 0 :(得分:1)

您可以将上面的所有代码放在while True循环中,打印后在else中的最后一行中写下break

所以开始是

while True:
    if rank == "expert":

,结束代码是

    if answer == "yes": #Starts an 'if' statemant
        print("OK") #Displays 'OK' which tells the user the programme will continue.
    else:
        print("Goodbye")
        break

答案 1 :(得分:1)

@ mrfred489的答案很好,但如果你面临这样的问题,一般来说,学习更多的Python和编程语言可能对你有很大帮助; google for Python初学者课程:)