Welcome 🤗! In the next ~4h we will cover:
A city skyline. You will later draw it as Exercise 3.
Hvordan skal Arthur bruge sin TA-tid? Baggrund: Arthur giver i øjeblikket skriftlig feedback på dine afleveringer. Alternativt kunne han bruge tiden på at holde en lektiecafé, hvor du får personlig støtte ansigt til ansigt. Han kan ikke gøre begge dele.
Svar 📊 Live poll:
Jeg foretrækker at beholde den skriftlige feedback på mine afleveringer.
Jeg foretrækker en lektiecafé i stedet for skriftlig feedback.
Jeg har ingen præference.
Jeg foretrækker noget andet end skriftlig feedback eller en lektiecafé.
Test¶
(20 min)
Learning goals¶
write void and value-returning functions that take parameters, and call them with positional and keyword arguments
explain the difference between returning a value and printing it
differentiate between local and global scope
modularize a task into functions using a top-down approach
use the random function
randintby importing and calling it
Preparation Review¶
Teach your peers¶

VIC CVUT, CC BY 3.0, via Wikimedia Commons
Explaining something is one of the best ways to find out what you don’t understand yet[1].
Make groups of 3-4. One of the students will be the instructor and the others will be listeners.
Steps:
(Optional) Find a talking stick and give it to the first instructor.
Each person takes one minute to pick a different question and agrees on this with others. Everyone takes individually one minute to think about how you’d explain it.
(optional) you can pick the question you found hardest, so the others can help you
The instructor explains the question to the others (max 3 min).
Each listener should ask at least one question.
If you get stuck, you can pass the stick to someone else for help.
Pass the stick to the next person and repeat until everyone has been the instructor.
Which concept or question do you still have problems with? Add one or two keywords to 📊 Live poll.
E: Teach your peers¶
Question pool¶
Why should you split a 100-line program into functions? Give two benefits.
Which task would you naturally write as a value-returning function, i.e., not void?
Take two strings as a parameter and produce their concatenation.
Take
nas a parameter and printntimesHello.Take no parameters and print
Welcome.Take
xandnas parameters and calculate .
The following code has a problem. Why?
def increment(x): print(x+1) y = increment(5) print(f"{y=}")Write a function that inputs a number
xand returns .Which one(s) lets you write
total = f(3) + f(4)?def f(x): return x+1def f(x): print(x+1)import math def f(x): math.sqrt(x)import math def f(x): print(math.sqrt(x))
You have the following code:
b = 0 def f(a): b = a + 1 return b def g(c): b = c + 1 return bIs there a difference between the global
b,binf(a), andbing? Which concept (calleds...) makes this possible?What does the following code output? Why?
a = 4 square_root_of_a = 0 def square_root(x, result): result = x**.5 square_root(a, square_root_of_a) print(square_root_of_a)Which line simulates a six-sided die?
random.randint(1, 6)random.choice(6)random.randrange(1, 6)random.uniform(1, 6)random.random(6)
Which of these calls is a syntax error?
print("Hello", "world")print("Hello", "world", sep="-", end="!\n")print(sep="-", end="!\n", "Hello", "world")print(sep="-", end="!\n")
You are designing a program that reads exam scores, computes the average, and prints a grade report. Which is the best first step in top-down design?
Write
mainthat calls placeholder functions such asdef read_exam_scores(): passWriting the
average()function first.Writing everything in one block and splitting it afterwards.
Drawing a flowchart the corresponds to the functionality of every line.
Coding¶
Group formation facilitation¶
Working with a different partner each time helps you:
see how someone else approaches a problem
get to know your peers
help others in our learning community.
The instructor/TA will facilitate group formation. Participation is optional.
Pick one of the three spots in the front:
🟪 Left: Pair programming
You shift between driver and navigator.
🔷 Middle: Tutoring (helper)
I’d like to help someone who is learning.
🟡 Right: Tutoring (learner)
I’d like help from someone more experienced.
If there are more learners than helpers, we may form groups of three, or you can pair-program instead.
E: Growth forecast refactoring¶
E: Shipping calculator¶
E: Random password generator¶
E: Triangle¶
E: Reflection¶
Let us revisit our learning goals:
write void and value-returning functions that take parameters, and call them with positional and keyword arguments
explain the difference between returning a value and printing it
differentiate between local and global scope
modularize a task into functions using a top-down approach
use the random function
randintby importing and calling it
An activity based on learning by teaching or Protege effect.