\(\renewcommand\AA{\unicode{x212B}}\)

Basic Python Exercises

  • Here we will try some exercises to get to grips with the basics of Python

Exercise 1

  • Write a program that prints out the square of the first 20 integers in a block such that the block is a rectangle of size 4x5. (Hint: One method uses the % (modulo) operator to test if a number is a multiple of another number. The answer is the remainder of the division of the lhs into whole parts, e.g. 4 % 1 = 0, 4 % 2 = 0, 4 % 3 = 1, 4 % 4 = 0)

Exercise 2

  • Write a program that prints out the first 25 Fibonacci numbers. (The Fibonacci sequence starts as with 0,1 and next number is the sum of the two previous numbers)
    • Extend the program to also print the ratio of successive numbers of the sequence.