-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path53_Python_If_Else.py
102 lines (85 loc) · 1.51 KB
/
53_Python_If_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Python If ... Else
print("Python If ... Else")
# If
print("\nIf...")
# Example 1
print("Example 1:")
a = 25
b = 99
if a < b:
print("a is less than b")
# Elif
print("\nElif...")
# Example 2
print("Example 2:")
c = 33
d = 33
if c > d:
print("c is greater than d")
elif c == d:
print("c and d is equal!")
# Else
print("\nElse...")
# Example 3
print("Example 3:")
e = 100
f = 100
if e > f:
print("e is greater than f")
elif e < f:
print("e is less than f")
else:
print("e is equal to f")
# Short hand if
print("\nShort hand if...")
# Example 4
print("Example 4:")
a1 = 5
b1 = 2
if a1 > b1: print("a1 is bigger")
# Short hand if...else
print("\nShort hand if...else")
print("Example 5:")
a2 = 99
b2 = 9
print("A2") if a2 > b2 else print("B2")
print("Example 6:")
a3 = 3
b3 = 3
print(">") if a3 > b3 else print("<") if a3 < b3 else print("=")
# And
print("\nAnd...")
print("Example 7:")
x = 25
y = 5
z = 1993
if x > y and z > y:
print("Both condition is True.")
# Or
print("\nOr...")
print("Example 8:")
if y > x or z > x:
print("Only one condition is True.")
# Not
print("\nNot...")
print("Example 9:")
if not x > z:
print("x is not greater than z")
# Nested if
print("\nNested if...")
print("Example 10:")
m = 33
if m > 10:
print("Value is:", m)
print("Value is greater than 10")
if m < 20:
print("But, value is less than 20")
else:
print("Also, value is greater than 20")
# The pass statement
print("\nThe pass statement:")
print("Example:")
p, q = 2, 1
if p > q:
pass
# Error will not occur