-
Notifications
You must be signed in to change notification settings - Fork 0
/
Control Flow (if, elif, else).py
53 lines (43 loc) · 1.25 KB
/
Control Flow (if, elif, else).py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# IF, ELSE, ELIF
# Adds logic to our code
# The if statement performs the task if the condition is true.
# The else statement performs a default when the if statement's condition is false.
# Else statements cannot exist on their own.
# The elif statement (short for else if) works in between if and else statements.
# Elif only performs a task when true, and the if statement is False.
a = 10; b = 25; c = 100; d = ("cat", "dog", "bird")
# if statement
if a == 10:
print('IF statement with one condition')
# if statement with 2 conditions
if a == 10 and b < 40:
print('IF with two conditions')
# nested if statement
if a == 10:
if b < 40:
print('Nested IF statement')
# if/else statement
if a == 20 and b < 40:
print('This statement will not be printed')
else:
print('IF/ELSE statement')
# nested if/else statement
if a ==10:
print('a is true')
if b < 40:
print('b is true')
else:
print('b is false')
else:
print('a is false')
if 'cat' in d:
print('cat is in tuple')
else:
print('cat is not in tuple')
# elif statements
print()
num = int(input('Enter a Number:- '))
if num >= 3:
print('Keep Looking !')
else:
print('Found a {}'.format(d[num]))