12 – Exercises

Introduction to Python

Author

Clemens Brunner

Published

February 2, 2026

Introduction

This section contains additional exercises to practice the concepts learned in the previous sections. This is still work in progress, so more exercises will be added over time.

Exercise 1

Write a function collatz that takes a positive integer n as an argument and returns a list of the Collatz sequence starting with n. The Collatz sequence is defined as follows: if n is even, the next number is half of n. If n is odd, the next number is three times n plus 1. The sequence ends when it reaches 1.


https://creativecommons.org/licenses/by-nc-sa/4.0/ This document is licensed under the CC BY-NC-SA 4.0 by Clemens Brunner.