-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_if_else.py
More file actions
40 lines (32 loc) · 786 Bytes
/
10_if_else.py
File metadata and controls
40 lines (32 loc) · 786 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
# 10 - Control Flow: if, elif, else
age = 18
# Basic if condition
if age >= 18:
print("You are an adult.") # condition is True
# if with else
if age < 18:
print("You are underage.")
else:
print("Access granted.") # age is not less than 18
# if, elif, else chain
score = 75
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C") # this block runs
else:
print("Grade: D or below")
# Multiple conditions
username = "admin"
logged_in = True
if username == "admin" and logged_in:
print("Welcome back, admin!") # both conditions are True
else:
print("Access denied.")
# Nested if example
x = 5
if x > 0:
if x < 10:
print("x is a positive single-digit number.") # nested condition