If Statements
An if statement lets your program make decisions based on conditions. It checks whether something is True or False. We can also tell the program to do xyz based on the input from the user.
Example: Imagine we ask the user for their age, and based on their age we can decide what the output or message will be displayed to them.
Code Example:
age = int(input("Enter your age: "))
if age >= 20:
print("You are allowed to drive a car!")
elif age >= 70:
print("You are a senior!")
else:
print("Please try later!")Last updated