L1 Python Introduction
L1 Python Introduction
Decomposi
tion
Abstractio
n
Algorithmi
c thinking
Abstraction
Abstraction is the process of removing
unnecessary details and including only
the relevant details.
Walkthrough
A. 2 + 12 / 2
B. 13
C. 7
▹ D. 8
Walkthrough
Identify
1 a = int(input()) variables
2 b = int(input())
3 avg = b + a / 2 assignment statements
4 print(avg)
5 max = a arithmetic expression
6 if b > max:
7 max = b Boolean expression (condition)
8 print(max)
a block of statements that may not be
executed
Worksheet 1
Identify: Answers
Selection recap
if condition
: You need a selection structure . (if-elif-
block of else) when there are multiple branches
statements
condition
and your program needs to select which
elif :
block of
one of them to follow.
statements
else:
You can use none, one, or multiple elif–blocks.
block of
statements You can use none, or one else–block.
Recap 1
Selection recap
1 from datetime import datetime Retrieve the current day of the week .
2 day = datetime.now().weekday() (explorer task)
3 if day < 4:
4 print("It’s a weekday")
5 remaining = 5 - day
6 print(remaining, "days until the weekend")
7 elif day == 4:
8 print("It’s Friday")
9 print("Just a day left until the weekend")
10 else:
11 print("It’s the weekend!")
Recap 2
A list of names
1 days = ["Monday", "Tuesday", The names for the days of the week can be
2 "Wednesday", "Thursday",
3
stored in a list .
"Friday", "Saturday",
4 "Sunday"]
Syntax: A comma-separated list of
values (items), in square brackets.
A list of names
A list of names
4 "Friday"
5 "Saturday"
6 "Sunday"
A list of names
4 "Friday"
5 "Saturday"
6 "Sunday"
5 "Saturday"
6 "Sunday"
5 "Saturday"
6 "Sunday"
5 "Saturday"
6 "Sunday"
5 "Saturday"
6 "Sunday"
5 "Saturday"
6 "Sunday"
3 5 "Saturday"
6 "Sunday"
6 "Sunday"
As seasons roll on by