Skip to content

Task 01: Fundamentals

a) Counting Sheep

Write a loop that counts sheep from 1 to 20. In each iteration it should print the number of counted sheep and the number of legs that these sheep have in total (4 per sheep).

Expected Output

1 sheep, 4 legs
2 sheep, 8 legs
3 sheep, 12 legs
20 sheep, 80 legs

b) Echo

This little program asks the user for input. It then prints the input that the user has provided. After that it again prints the input value except for the first letter. Then it prints the input without the first two letters, and so on until no letters are left.

Example Output

Which word should I repeat? Echo


Hint: Check out Python’s built-in input(…)-function!

c) 3x+1

The Problem

This is a famous and not yet fully solved problem in mathmatics. Here are the rules:

  • Start with any positive integer number x
  • If x is even, x = x/2
  • If x is odd, x = 3x + 1

Eventually your sequence will end up in the loop 4 → 2 → 1 → 4 … (The unsolved part is that there is no proof yet that this always happens.)

Now you!

Implement a loop that generates and prints the sequence for any given starting number. You can either set the starting value in a variable at the beginning of your program or read it from a user input. The loop should stop if x reaches one of the three numbers (4, 2, or 1) that are known to form an endless cycle.

Example Output:

Starting Value: 5
4 - 2- 1, Yeah, I know...