day 6 python series
day 6 python series
1. if statement
2. if-else statement
3. if-elif-else statement
1. if Statement
Syntax:
if condition:
# code to execute if condition is true
Example:
age = 20
if age >= 18:
print("You are eligible to vote.")
2. if-else Statement
The if-else statement evaluates a condition and executes one block
of code if the condition is true, and another block if the condition is
false.
Syntax:
if condition:
# code to execute if condition is true
else:
# code to execute if condition is false
Example:
age = 16
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
3. if-elif-else Statement
Syntax:
if condition1:
# code to execute if condition1 is true
elif condition2:
# code to execute if condition2 is true
else:
# code to execute if none of the conditions are true
Example:
score = 85
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
else:
print("Grade: C")
Assignment
1)day=1Sunday
Day=2 Monday
Day=3Tuesday
……..
Day=7Saturday
Day=input()
If day==1:print(Sunday”)
Elif day==2:
Print(Monday)
……
70
Else(“no day found”)