if Statement
Table of Contents
Toggle
The if statement lets your program make decisions.
Let’s explore different ways to use it with properly formatted examples.
temperature = 35
if temperature > 30:
print("It’s a hot day!")
age = 16
if age >= 18:
print("You are eligible to vote")
else:
print("You are not eligible to vote")
marks = 85
if marks < 40:
print("Fail")
elif marks >= 75:
print("Distinction")
else:
print("Pass")
num = 15
if num > 0:
if num % 2 == 0:
print("Positive even number")
else:
print("Positive odd number")
amount = 1200
discount = 0
if amount > 2000:
discount = 20
elif amount > 1000:
discount = 10
else:
discount = 5
final_amount = amount - (amount * discount / 100)
print("Discount applied:", discount, "%")
print("Final bill:", final_amount)
