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
1#Conditionals statements in python
2#'=' conditionals statements
3a = 123
4b = 123
5
6if(a==b):
7 print('True')
8
9#<, > conditionals statements
10
11a = 2
12b = 45
13
14if(a<b):
15 print('A is smaller than B')
16
17
1answer = input(":")
2if answer == "lol":
3 print("haha")
4else:
5 print("not haha")
6 exit()
7
8please note that the exit() command is optional and is not necessary.
1if expression1:
2 statement(s)
3elif expression2:
4 statement(s)
5elif expression3:
6 statement(s)
7else:
8 statement(s)
9
1if num > 0:
2 print("Positive number")
3elif num == 0:
4 print("Zero")
5else:
6 print("Negative number")