Conditional_Statements_Classwork_and_Homework
Conditional_Statements_Classwork_and_Homework
1. `if` Statement
Executes a block if the condition is True.
age = 18
if age >= 18:
print("You are an adult.")
2. `if-else` Statement
Choose between two blocks based on the condition.
age = 16
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
score = 75
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
else:
print("Grade: F")
4. Nested `if-else`
An `if` or `else` block containing another `if-else`.
age = 20
has_id = True
if age >= 18:
if has_id:
print("You can enter.")
else:
print("ID required.")
else:
print("You are too young.")