WORKSHEET-1
SUBJECT: COMPUTER SCIENCE
LESSON: PYTHON PROGRAMMING TOPIC: CONDITIONAL STATEMENTS
NAME:__________________________ CLASS:_______________________
LEARNING OBJECTIVE: To enable students to control the flow of a program by
mastering the usage of if, else, and elif statements to make decisions based on
specific conditions.
if.. statement:
if statement: The if statement is used to execute a block of code only if a condition is true.
Syntax: Flowchart:
if condition:
statement 1
statement 2
Example:
n=10
if n>0:
print("The number is positive")
Activity 1: Code Debugging
Identify and fix the errors in the given python code
weather = "rainy
If weather = "rainy"
Print("Don’t forget your Umbrella")
Activity 2: Fill in the blanks
with appropriate conditional statements and suitable operator.
age = 16
____ age ____ 18:
print("You can vote")
Activity 3: Code Analysis:
Analyze the following code snippets and predict their output.
temperature = 25
if temperature > 20:
print("It's a good day for a picnic!")
Answer the following questions:
1. What is the condition being checked in the if
statement?
2. What message will be printed if the
condition is True?
3. What will be printed if the value of
temperature is 18? Explain.
if…else… statement:
if-else statement: The if statement will check the condition; if the condition is true then if block is
executed. If the condition is false then else block is executed.
Syntax: Flowchart:
if condition:
statement 1
statement 2
else:
statement 3
statement 4
Example:
n=-5
if n>0:
print("The number is positive")
else:
print("The number is negative")
Activity 1: Code Debugging
Identify and fix the errors in the given python code
age = 16
if age => 18:
print("You are eligible to vote.")
Else age < 18
print("You are not eligible to vote.")
Activity 2: Code Analysis:
Analyze the following code snippets and predict their output.
distance = 15 # distance to the delivery location in kilometers
if distance > 10:
print("This location is quite far, additional charges may apply.")
else:
print("The location is nearby, enjoy free delivery!")
Answer the following questions:
1. What is the value of the distance variable?
2. What message will be printed if the distance is exactly 10
kilometers?
3. What happens if the distance variable is assigned a
negative value?
4. If the distance is 8 kilometers, which message will be
printed?
Activity 3: Code Writing
Lab Activity
1. Python program to accept the age from the user and check whether he/she is eligible to
vote or not.
2. Write a Python program to find the smallest among 2 numbers.
3. Write a Python program to find whether a number is odd or even.
if…elif…else… statement:
if-elif-else statement: The if-elif-else statement allows you to check multiple conditions and
execute a different block of code for each condition
Syntax: Flowchart:
if condition:
statement 1
statement 2
elif condition:
statement 3
statement 4
else:
statement 5
statement 6
Example:
n=0
if n > 0:
print("The number is positive")
elif num < 0:
print("The number is negative")
else:
print("The number is zero")
Activity 1: Code Debugging
Identify and fix the errors in the given python code
mark = 85
if mark => 90:
print("A grade”)
Elif mark >= 80
print("B grade”)
else:
print("C grade”)
Activity 2: Code Analysis:
Analyze the following code snippets and predict their output.
weather = input(“sunny/rainy”)
if weather == "sunny":
print("It's a great day for a picnic!")
elif weather == "rainy":
print("Don't forget your umbrella!")
else:
print("Enjoy the day!")
Answer the following questions:
1. Suppose you wake up to a rainy morning. What advice might
this program give you?
2. How might you modify this program to include more weather
conditions, such as cloudy or snowy?
Activity 3: Code Writing
Lab Activity
1. Python program to find the largest among 3 numbers.
2. Python program to input the marks and print the grades accordingly.
3. Create BMI (Body Mass Index) calculator in Python.
4. Create a simple calculator program.
Nested if statements:
Nested if statement: Nesting is the process of using one or more if statements inside another if
statement to handle more complex conditions.
Syntax: Flowchart:
if condition:
if condition:
statement 1
else:
statement 2
else:
statement 3
Activity 1: Code Analysis:
Analyze the following code snippets and predict their output.
age=int(input(“Enter the age of the student-“))
mark=int(input(“Enter the mark of the student-“))
if age > 18:
if mark>65:
print("You’ll get admission in ABC college”)
else:
print("You’ll not get admission in ABC college”)
else:
print("Too young to get admission”)
Answer the following questions:
1. How does this code determine whether a
student is eligible for admission to ABC
college?
2. How does the code handle the scenario where
a student's age is less than or equal to 18?
3. What message does the code print if a student
is older than 18 but has marks below the 65?
Activity 2: Code Writing
Lab Activity
1. Python program to find the largest among 3 numbers using nested if.