Skip to content

Intermediate Exercises

These exercises require you to know about

  • Variables and data types
  • Conditionals
  • While-Loops

They are intended to help you become familiar with the very basics of programming and your tools.

A simple Countdown

Write a program to output a simple countdown from 10 to 0. When the countdown has reached 0, also output the word Liftoff. Start with a variable to hold your current_number and use a while-loop to deal with the printing and updating the number.


Write a program that reads the users input. Depending on the input given, it should do different things:

Input Reaction
ping Output pong
pong Output ping
empty string Do nothing
anything else Output That is not Ping-Pong

Consider first what an empty string is and how you might check for it.

A less simple Countdown

Write a programm that again implements the countdown from 10 down to 0. This time, after reaching the number 6, it shall output Starting engine once. After reaching the number 4, it shall output the words and counting after each number, except for the number 0, which is instead followed by Liftoff instead.

Expected Output
6 Starting engine
4 and counting
3 and counting
2 and counting
1 and counting
0 Liftoff


Your colleague drafted a code for a simple temperature control for their experimental setup. Their idea was to repeatedly raise or lower the temperature by a fraction to get closer to the allowed temperature range with each step. This is done to prevent thermal shocks due to extreme temperature changes. Sadly it does not work as expected and instead often gets caught in an infinite loop.

What causes the issue? Make suggestions to fix it.

temperature = float(input("Starting Temperature in °C: "))

allowed_min = 9.5
allowed_max = 9.6

while not (
    (temperature >= allowed_min) and
    (temperature <= allowed_max)
    if temperature > allowed_min:
        temperature = temperature / 1.25
    elif temperature < allowed_max:
        temperature = temperature * 1.25
    print("Set temperature to", temperature, "°C next")

The Lab Equipment Dispenser

About this Task

This task is a bit more complex and designed to familiarize you more with the subtle challenges of real-live programming.

  • While the programming structures that you know are perfectly sufficient to solve the task, the ways in which to apply them might not be obvious.
  • It is more complex than the tasks you have seen before. Instead of solving it in one go, you may want to solve a part of it, try that out and then continue on the next part.
  • It has a vague specification, meaning you are not told all details of the problem. In the cases where you lack information it is up to your best judgement to fill in the blanks. As long as the program fulfills the specified behaviour, it is considered correct.

Your lab is is supposed to get a new dispenser for safety equipment. Management decided that we can develop it cheaper in-house and tasked you with writing the bookkeeping program for it.

Some of your colleagues already went through a brain-storming session and came up with a flowchart that describes how the machine is supposed to work. They drew you this diagram before they left for a conference:


Create a program that implements the specified behaviour.