0% found this document useful (0 votes)
4 views3 pages

4.notes Conditional Statements

The document provides an overview of conditional statements in Python, including 'if', 'if..else', and 'if..elif..else' statements, which control code execution based on conditions. It includes syntax examples and a lab activity for students to create a program that assigns grades based on user input marks. Additionally, there is a NIM activity for students to write a program that identifies the meanings of colors in the UAE flag.
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)
4 views3 pages

4.notes Conditional Statements

The document provides an overview of conditional statements in Python, including 'if', 'if..else', and 'if..elif..else' statements, which control code execution based on conditions. It includes syntax examples and a lab activity for students to create a program that assigns grades based on user input marks. Additionally, there is a NIM activity for students to write a program that identifies the meanings of colors in the UAE flag.
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

CONDITIONAL STATEMENTS IN PYTHON

SUBJECT: COMPUTER SCIENCE

CLASS: 8

Learning Objective:
Students will use Python conditional statements to solve problems and
make decisions based on given conditions.
Introduction:
Conditional statements in Python allow you to execute different blocks of code
depending on whether a certain condition is true or false.
In Python, if, if..else, and if..elif..else… are conditional statements used to control
the flow of execution based on certain conditions
1. if Statement
The if statement is used to execute a block of code only if a condition is
true.

Syntax Example
if condition: age = 18
statement 1 if age >= 18:
statement 2 print("You are eligible to vote.")

2. if..else Statement
The if-else statement allows you to execute one block of code if the
condition is true, and another block of code if the condition is false.

Syntax Example
if condition: age = 16
statement 1 if age >= 18:
statement 2 print("You are eligible to vote.")
else: else:
statement 3 print("You are not eligible to
statement 4 vote.")

3. 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 Example
if condition: marks = 75
statement 1 if marks >= 90:
statement 2 print("Grade: A")
elif: elif marks >= 80:
statement 3 print("Grade: B")
statement 4 elif marks >= 70:
else: print("Grade: C")
statement 5 else:
statement 6 print("Grade: D")

Lab Activity:
Write a Python program that accepts marks as input from the user and displays
the corresponding grade along with feedback, based on the grading table below:
If the entered mark is less than 0 or greater than 100, display a message asking
the user to enter a valid mark.

Marks Range Grade Feedback


90 - 100 A+ Excellent performance!
80 - 89 A Very good! Keep it up!
70 - 79 B+ Good job, aim higher!
60 - 69 B Satisfactory, improve more.
Marks Range Grade Feedback
50 - 59 C Fair, work harder.
40 - 49 D Needs improvement.
Below 40 Fail You must try again.

NIM Activity:
Write a Python program that asks the user to enter a color of the UAE flag and
print the meaning of the entered color. If the input is not part of the UAE flag,
then print “That is not a color of the UAE flag”.

• Red represents bravery, strength, and courage.


• Green represents hope, joy, and prosperity.
• White represents peace and honesty.
• Black represents the defeat of enemies and strength of mind.

You might also like