-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path04_Conditional_Statements.py
More file actions
63 lines (49 loc) · 997 Bytes
/
04_Conditional_Statements.py
File metadata and controls
63 lines (49 loc) · 997 Bytes
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
# If condition
age = 19
if age > 18:
print("You are an adult.")
# Short Hand if
if age > 18 : print("You are eligible to vote.")
# If-else condition
age = 10
if age <= 12:
print("Travel for free")
else:
print("Pay for ticket")
# Short Hand if-else
marks = 45
res = "Pass" if marks >= 40 else "Fail"
print(f"Result: {res}")
# Elif condition
age1 = 25
if age1 <= 12:
print("Child")
elif age1 <=19:
print("Teenager")
elif age1 <=30:
print("Young Adult")
else:
print("Adult")
# Nested if condition
age2 = 70
is_member = True
if age2 >=60:
if is_member:
print("30% senior discount")
else:
print("10% senior discount")
else:
print("No senior discount available")
# Ternary Conditional Statement
age3 = 19
s = "Adult" if age >=18 else "Minor"
print(f"Status: {s}")
# Match-Case Statement
number = 1
match number:
case 1:
print("One")
case 2 | 3:
print("Two or Three")
case _:
print("Other number")