Day 3
Day 3
Programming
Essentials
DAY 3 – Control
Structures (Selection)
Topics
01 Control Structures
02 Type Structures
03 Sequence
04 Selection
05 Conditional Operators
06 Compound Conditions
Control Structures
Selection
Selection used for decisions, branching – choosing
between 2 or more alternative paths.
Iteration
Repetition used for looping, i.e. repeating a
piece of code multiple times in a row.
Types of Structure {}
Sequence
Please enter three
numbers
The simplest structure
Find the sum of the Control flows from one statement to the next
three numbers
Entry Exit
Example: Sequence
A program that computes and prints the net pay of an employee
contains the following code:
if condition:
statement1
if condition:
statement1
statement2
if condition:
statement1
elif condition:
statement2
else:
statement3
Conditional Operators
❑Equals: a == b
❑Not Equals: a != b
❑Less than: a < b
❑Less than or equal to: a <= b
❑Greater than: a > b
❑Greater than or equal to: a >= b
Some Common Errors
Using > instead of >=
Example: “Write a program that would give customers over age 60 a discount
of 20%”
❑ The phrase “over age 60” is not clear. Does it include the age 60 or not?
Clarify what it means.
❑ Similar phrases that have unclear meaning are: “not more than”, “at
least”, “not under”.
Day 3
Activity 1
● Write a program that will compute Name: Vinz
for the students average Math: 80
● The user will input the following: Science: 90
❑ Name English: 85
❑ Math Average: 85.0
❑ Science
❑ English POSSIBLE OUTPUT:
● If the average is equal and above Output 1:
75 status is Passed else You Congratulations! You passed
Failed the semester the semester. But you need
to re-enroll English subject
Output 2:
Sorry, You Failed the
semester
Day 3 Activity 1
Compound CoNditions
❑Have more than 1 conditional expression
❑The result of the compound expression depends on the
individual result of each condition
Format:
(condition1) and (condition2)
(condition1) or (condition2)
Day 3
Activity 2
● Write a program that will check the employees
years in service and office.
● The user will input number for years and in
service and the following offices (IT, ACCT, HR)
● Check the following conditions
Day 3 Activity 2
Built-in Methods
❑ isupper() - Returns True if all characters in the string
are upper case
❑ islower() - Returns True if all characters in the string
are lower case
❑ isdigit() - Returns True if all characters in the string
are digits
❑ isalpha() - Returns True if all characters in the string
are in the alphabet