0% found this document useful (0 votes)
5 views13 pages

Lesson 3. USING IF ELSE STATEMENTS

This document explains the use of if-else statements in Python for performing conditional programming. It provides examples, including a PIN verification program and a score remark program, illustrating how to evaluate conditions and display corresponding messages based on user input. The document also includes pseudocode and flowcharts to aid understanding of the concepts presented.

Uploaded by

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

Lesson 3. USING IF ELSE STATEMENTS

This document explains the use of if-else statements in Python for performing conditional programming. It provides examples, including a PIN verification program and a score remark program, illustrating how to evaluate conditions and display corresponding messages based on user input. The document also includes pseudocode and flowcharts to aid understanding of the concepts presented.

Uploaded by

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

ICT 10

Lesson
3
Using
If-Else
Statements
UNIT 3: Performing Conditional
Programming Using Python
If-else conditional structure
 evaluates a condition and provides
statements when the answer is either true
or false.

True
Condition Statements

False

Statements
If-else statement
 adds another statement when the
condition is false.

If-else in Python
 adds else and its statement.
In Python, its syntax is:

if condition:
statement/s
else:
statement/s
 The first half of the syntax is the same as the if
statement.
 The else with a colon (:) is added to the next line.
 The statement/s for the else is placed afterward.
Example 1: PIN
Let us create a program that
asks the user to enter his or her PIN.
The program displays a message if
the PIN is correct. Else, it displays
another message if the PIN is
incorrect.
Pseudocode:
1. Assign the PIN to a variable.
2. Display the instruction to the user to enter his or
her PIN.
3. Accept the entered PIN.
4. Evaluate if the entered PIN is the same as the
stored PIN.
5. Display
Displaya message
another when the PIN
message is correct.
when the PIN is
incorrect.
Start

Code = “1234”

Flowchart Output
“Please enter
the PIN:”

Enter PIN

Yes Output “The


If PIN = PIN is
code?
correct.”
No

Output “The
PIN is
incorrect.” End
Program:
#PIN
#Display a message when the PIN is the same as the
stored PIN.
#”Else, it displays another message.

code = “1234”
PIN = input(“Please enter the PIN: ”)
if PIN ==code:
print(“The PIN is correct. ”)
else:
print(“The PIN is incorrect. ”)
Output:
 The program displays another message
if the user enters a different PIN.

Please enter the PIN: 5678


The PIN is incorrect
Example 2: Score Remark
Let us create a program that asks
the user to enter his or her score in a 10-
point quiz. The program displays the
remark “You passed the quiz!”, else it
displays the remarks “Oops. Do better
next time.”
Program:
#Score Remark
#Display the message “You passed the quiz!”, if the score is
passing.

passingscore = “7.5”
score = float(input(“Please enter your score: ”))
if score >=passingscore:
print(“You passed the quiz!”)
else:
print(“Oops. Do better next time.”)
Output:
 The program displays another remark if
the score did not meet the passing mark.

Please enter your score: 5


Oops. Do better next time.

You might also like