Добавить
Уведомления

Constructing if elif else statement on python

#Asking for user input #.lower()turns all user input to lowercase therefore for programming purposes JUNE equals june answer = input("What month is it? ").lower() #Depending on what user answers the output varies #if statement can be used on its own #List all acceptable conditions separated by or keyword if answer == "december" or answer == "january" or answer == "february": print("It's winter") #Elif (as in else if) branch works exactly the same. elif must be preceded by if statement elif answer == "march" or answer == "april" or answer == "may": #You can have multiple elif brances print("It's spring") elif answer == "june" or answer == "july" or answer == "august": print("it's summer") elif answer == "september" or answer == "october" or answer == "november": print("it's autumn") #Use else for: if none of the above applies, do this.. else: print("Unrecognised month..") #Run a few tests to see the program works as expected. #Pressing F5 will run the program

Иконка канала Введение в Python
4 подписчика
12+
16 просмотров
2 года назад
12+
16 просмотров
2 года назад

#Asking for user input #.lower()turns all user input to lowercase therefore for programming purposes JUNE equals june answer = input("What month is it? ").lower() #Depending on what user answers the output varies #if statement can be used on its own #List all acceptable conditions separated by or keyword if answer == "december" or answer == "january" or answer == "february": print("It's winter") #Elif (as in else if) branch works exactly the same. elif must be preceded by if statement elif answer == "march" or answer == "april" or answer == "may": #You can have multiple elif brances print("It's spring") elif answer == "june" or answer == "july" or answer == "august": print("it's summer") elif answer == "september" or answer == "october" or answer == "november": print("it's autumn") #Use else for: if none of the above applies, do this.. else: print("Unrecognised month..") #Run a few tests to see the program works as expected. #Pressing F5 will run the program

, чтобы оставлять комментарии