Computer Science 110
Fundamentals of Computing

Denison

Loop Practice

Write Python functions to solve each of the following problems:

  1. Write a loop that prints the first ten natural numbers (1, 2, ...) with each number on its own line.
  2. Write a loop that prints the first eight natural numbers (1, 2, ...) with all the numbers on a single line.
    There should be a space between each pair of numbers.
  3. Write a loop that prints the integers 10 down to 0 (i.e. backwards), and on separate lines.
  4. Write a loop that prints the even integers from 22 through 36 inclusive on separate lines.
  5. Write a loop that prints the first ten multiples of 17. (17, 34, 51, ...)
  6. Write a loop that prints the first ten numbers on one line (with spaces in between) and then repeats
    this 5 times, so that we have 5 rows of the numbers 1 through 10. Hint: think about putting one loop
    inside another.
  7. Write a loop that prints the following:
    1 1 1 1
    2 2 2 2
    3 3 3 3
    4 4 4 4
    5 5 5 5
  8. Write a loop that prints the first 16 powers of 2, each on separate lines.

Name the functions exercise1(), exercise2(), exercise3(), etc. and put all eight function definitions in one Python source file named loops.py followed by an invocation for each function. Make sure you include a comment block with your name, the date, and a description of the program.