2016-06-13 2 views
0

이것은 현재 내 코드이므로 프로그램을 다시 반복 할 것인지 묻는 메시지가 필요합니다. while 루프를 사용해야한다는 것을 알고 있지만 막혀 있습니다.사용자에게 Python 프로그램을 반복 할 것인지 묻습니다.

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) 

답변

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 
관련 문제