-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path44)Elif_Program.py
More file actions
61 lines (46 loc) · 1.27 KB
/
44)Elif_Program.py
File metadata and controls
61 lines (46 loc) · 1.27 KB
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
# The Elif Keyword:
# The elif keyword is Python's way of saying
# "if the previous conditions were not true, then try this condition".
# The elif keyword allows you to check multiple expressions for True and
# execute a block of code as soon as one of the conditions evaluates to True.
a = 33
b = 33
if b > a :
print("b is greater than a")
elif a == b :
print("a and b are equal")
# Multiple Elif Statements
# You can have as many elif statements as you need.
# Python will check each condition in order and
# execute the first one that is true.
score = 75
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade B")
elif score >= 70:
print("Grade C")
elif score >=60:
print("Grade D")
elif score >= 50:
print("Grade E")
# When to Use Elif
# Use elif when you have multiple mutually exclusive conditions to check.
# This is more efficient than using multiple separate if statements because Python stops checking once it finds a true condition.
#Example
#Day of the week Checker
day = 3
if day == 1:
print("Monday")
elif day == 2:
print("Tuesday")
elif day == 3:
print("Wednesday")
elif day == 4:
print("Thrusday")
elif day == 5:
print("Friday")
elif day == 6:
print("Saturday")
elif day == 7:
print("Sunday")