【问题标题】:Ask the user if they want to repeat a python program询问用户是否要重复 python 程序
【发布时间】:2016-06-14 03:05:15
【问题描述】:

这是我现在的代码,我需要询问用户是否要再次重复该程序。我知道你需要在这里使用 while 循环,但我卡住了。

userinput = eval(input("Enter the month as a number "))
results = userinput

if results == 1:
month = "January"
elif results == 2:
month = "February"
elif results == 3:
month = "March"
elif results == 4:
month = "April"
elif results == 5:
month = "May"
elif results == 6:
month = "June"
elif results == 7:
month = "July"
elif results == 8:
month = "August"
elif results == 9:
month = "September"
elif results == 10:
month = "October"
elif results == 11:
month = "November"
elif results == 12:
month = "December"

print("Your birth month of", month)

【问题讨论】:

    标签: python-3.x


    【解决方案1】:

    可能有上百万种方法可以提高效率,但这是您正在寻找的基本结构。

    endFlag = False
    while endFlag == False:        
        # your code here
        ui = input("Would you like to repeat the program again? Y/N")
        if ui == 'N':
            endFlag = True
    

    【讨论】:

      猜你喜欢
      • 2013-04-18
      • 1970-01-01
      • 1970-01-01
      • 2018-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多