GitHub Education Benefits Application¶
(10m)
Go to Education benefits and Start an application, to have free access to the tools we will use.
Reading - input, extra print features and f-strings¶
(1h)
(if you don’t know what
float(input())does), read the section 2.6 Reading input from the keyboard.from p. 94 (More about the
printfunction) to p. 143 (Algorithm workbench, including)Also do the review questions beginning p.139. Skip the ones that you did not read about.
You can skip the Turtle section
Concepts:
input()Reading an integer, floating point number and string
extra
printfeaturesend=sep=for arguments\n,\t,\"
f-strings
also see Print debugging
Placeholder expressions,
f"{a+b}"Formatting values, .e.g.,
{n:.2f},{n:%},{n:,}Min field width,
{n"12,.2f"}Aligning values,
{n:>10},{n:^10}, etc
Named constants
magic numbers
UPPER_CASE
Reading - Decision structures and Boolean Logic¶
(3h) Reading PDF.
Until p.196, including Algorithm Workbench.
Concepts:
1.
ifstatementcontrol structure (remember #big3)
sequence structure
decision (selection) structure
single alternative decision structure
Boolean expressions and relational operators
>,<,>=,<=,==,!=
Single line
if:if cond: statement
2.
if-elseeffect of indendation
3. comparing strings
==,!=>, etc, for alphabetical sort
4. nested decision structures,
if-elif-elsestatementinstead of
if-else-if-else...
5. logical operators
and,or,notshort-circuit evaluation (for saving time)
6. Boolean variables
used as flags: does a specific condition exist?
bool
7. Conditional expressions
variable = value1 if condition else value2
8. assignment expressions and walrus operator
:=9. Turtle: determining the state
xcor(),ycor().heading()isdown()isvisible()pencolor()fillcolor()bgcolor()pensize()hit the target game
Reading - Repetition structures¶
(3h)
Until p.255, including Algorithm Workbench.
Concepts:
1. Introduction
Disadvantages of duplicated code
Condition- vs count-controlled loops
2.
whilecondition-controlled loopsyntax
whileis a pretest loopinfinite loops
whileas a count-controlled loopsingle-line
whileloops
3.
forcount-controlled loopsyntax,
for n in [1, 2, 3]: print(n)(lists introduced later)rangefunctionusing the target variable inside the loop, e.g., squaring the number
letting the user control the number of iterations (
range(n))Generating a descending sequence (
range(10, 1, -1))
4. Calculating a running total
total = total + nAugmented assignment operators:
+=,-=,*=,/=,%=,//=,**=
5. sentinels
6. Input validation loops
while input_not_correct: prompt_user()using the Walrus
:=:while (inp := input()) != "y"
7. Nested loops
e.g.,
for row in range(10): for col in range(10) : f()
8. Using
break,continue, andelsewith loopsshould be used with great caution — make the code less readable
while cond: f(); else: g()
9. Turtle: Using loops to draw designs
We meet in X2.38 again (instead of Robotlab)¶
I modified Semester schedule 📆