Assignment 13 — Nesting
Due Tuesday, September 27
Program digit_box.py
- Get an integer n from the user.
- Print an n-by-n grid of one-digit numbers, whose rows are numbered 0 to n-1 and columns are numbered 0 to n-1.
- The digit in the r th row, c th column is to be the last digit of the product r × c.
Two possible program runs
Enter integer: 4
0 0 0 0
0 1 2 3
0 2 4 6
0 3 6 9
Enter integer: 9
0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8
0 2 4 6 8 0 2 4 6
0 3 6 9 2 5 8 1 4
0 4 8 2 6 0 4 8 2
0 5 0 5 0 5 0 5 0
0 6 2 8 4 0 6 2 8
0 7 4 1 8 5 2 9 6
0 8 6 4 2 0 8 6 4
Observations
- The last digit of a base 10 number equals the remainder of that number when divided by 10. The
%
is a Python operator for that.
- Since the number of rows n is user-provided, a loop is necessary to process each row of the digit table.
- Since the number of columns per row also comes from n, a loop is necessary to process each row.
- Because the column processing happens for every row, the loop to process the rows will contain a loop to process the columns for a row; i.e., nested looping.