1usrinput = input(">> ")
2if usrinput == "Hello":
3 print("Hi")
4elif usrinput == "Bye":
5 print("Bye")
6else:
7 print("Okay...?")
8
1# IF ELSE ELIF
2
3print('What is age?')
4age = int(input('number:')) # user gives number as input
5if age > 18:
6 print('go ahead drive')
7elif age == 18:
8 print('come personaly for test')
9else:
10 print('still underage')
11
1The elif statement allows you to check multiple expressions for TRUE
2and execute a block of code as soon as one of the conditions evaluates
3to TRUE. Similar to the else, the elif statement is optional. However,
4unlike else, for which there can be at most one statement, there can
5be an arbitrary number of elif statements following an if.
6
7if expression1:
8 statement(s)
9elif expression2:
10 statement(s)
11elif expression3:
12 statement(s)
13else:
14 statement(s)
15
1if num<5:
2 print('Num less than 5')
3elif 5<= num <=9:
4 print('Num between 5 and 9')
5else:
6 print('Num more than 9')
1if num==5:
2 print("Num equal to 5")
3elif num > 5:
4 print("Num more than 5")
5else:
6 print("Num smaller than 5 but not equal to 5")
1def e(x):
2 if x == "Sunny" and x == "sunny":
3 print('Remember your sunglasses!')
4 elif x == "Rainy" and x == "rainy":
5 print('Do not forget your umbrella!')
6 elif x == 'Thunderstorm' or x == 'thunderstorm' or x =='Stormy' or x == 'stormy':
7 print('Stay Home!')
8
9x = input('What is the weather?')