Times table
Inputs
n is a whole number from 0 to 8.
Your tasks
- Create an empty list
table. - Use an outer loop for each row number
rfrom 1 up to and includingn. In it, build a listrowwith an inner loop for each column numbercfrom 1 up to and includingn, addingr * c. - Add
rowtotableafter the inner loop ends. - Complete
timesTableso it returnstable. Return it, do not print it.
Example
With n = 3, timesTable returns [[1, 2, 3], [2, 4, 6], [3, 6, 9]].
Rules
- If
nis 0, return an empty list.
Test data
TEST DATA 1: n is 3
TEST DATA 2: n is 0
Practice focus
Nested loops compare every pair and build rows. The slow, simple answer to most problems is two loops. Knowing it is what lets you see how to beat it.