0% found this document useful (0 votes)
6 views

day 6 python series

The document explains conditional statements in Python, which are used to control the flow of a program based on different conditions. It covers three types: if statements, if-else statements, and if-elif-else statements, providing syntax and real-time examples for each. Additionally, it includes a simple assignment task related to identifying days of the week based on input.

Uploaded by

naveen.azure02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

day 6 python series

The document explains conditional statements in Python, which are used to control the flow of a program based on different conditions. It covers three types: if statements, if-else statements, and if-elif-else statements, providing syntax and real-time examples for each. Additionally, it includes a simple assignment task related to identifying days of the week based on input.

Uploaded by

naveen.azure02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Day-6 Python programming series

What are Conditional Statements?

Conditional statements are used to perform different actions based on


different conditions. They help you to control the flow of your
program and make decisions.

Types of Conditional Statements in Python

1. if statement
2. if-else statement
3. if-elif-else statement

Let's look at each of them with real-time examples.

1. if Statement

The if statement evaluates a condition and executes the block of code


within it if the condition is true.

Syntax:
if condition:
# code to execute if condition is true

Example:
age = 20
if age >= 18:
print("You are eligible to vote.")

Real-time Example: Imagine you're at an amusement park and you


need to check if a person is tall enough to ride a rollercoaster.
height = 160 # height in cm
if height >= 150:
print("You can ride the rollercoaster!")

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.")

Real-time Example: Checking if the temperature is above freezing


point.
temperature = 10 # temperature in Celsius
if temperature > 0:
print("The water is in liquid state.")
else:
print("The water is frozen.")

3. if-elif-else Statement

The if-elif-else statement allows you to check multiple conditions,


executing different blocks of code for each condition.

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")

Real-time Example: Deciding what mode of transport to take based


on distance.
distance = 5 # distance in km
if distance < 1:
print("You should walk.")
elif distance < 5:
print("You should take a bicycle.")
else:
print("You should drive a car.")

Assignment
1)day=1Sunday
Day=2 Monday
Day=3Tuesday
……..
Day=7Saturday

Day=input()
If day==1:print(Sunday”)
Elif day==2:
Print(Monday)
……
70
Else(“no day found”)

You might also like