Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Welcome 🤗! In the next ~4h we will cover:

A city skyline. You will later draw it as .

A city skyline. You will later draw it as Exercise 3.

Test

(20 min)

Accept the assignment

Learning goals

Preparation Review

Teach your peers

VIC CVUT, CC BY 3.0, via Wikimedia Commons

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:

  1. (Optional) Find a talking stick and give it to the first instructor.

  2. 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

  3. 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.

  4. Pass the stick to the next person and repeat until everyone has been the instructor.

  5. Which concept or question do you still have problems with? Add one or two keywords to 📊 Live poll.

E: Teach your peers

Question pool

  1. Why should you split a 100-line program into functions? Give two benefits.

  2. 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 n as a parameter and print n times Hello.

    • Take no parameters and print Welcome.

    • Take x and n as parameters and calculate xnx^n.

  3. The following code has a problem. Why?

    def increment(x):
      print(x+1)
      
    y = increment(5)
    print(f"{y=}")
  4. Write a function that inputs a number x and returns x3x^3.

  5. Which one(s) lets you write total = f(3) + f(4)?

    •  def f(x):
         return x+1
    •  def f(x):
         print(x+1)
    •  import math
       def f(x):
         math.sqrt(x)
    •  import math
       def f(x):
          print(math.sqrt(x))
  6. You have the following code:

    b = 0
    
    def f(a):
      b = a + 1
      return b
    
    def g(c):
      b = c + 1
      return b

    Is there a difference between the global b, b in f(a), and b in g? Which concept (called s...) makes this possible?

  7. 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)
  8. 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)

  9. Which of these calls is a syntax error?

    1. print("Hello", "world")
    2. print("Hello", "world", sep="-", end="!\n")
    3. print(sep="-", end="!\n", "Hello", "world")
    4. print(sep="-", end="!\n")
  10. 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?

    1. Write main that calls placeholder functions such as def read_exam_scores(): pass

    2. Writing the average() function first.

    3. Writing everything in one block and splitting it afterwards.

    4. Drawing a flowchart the corresponds to the functionality of every line.

Coding

Group formation facilitation

Working with a different partner each time helps you:

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:

Footnotes