🎯 Activity Goals
- Apply your knowledge of
forloops and therange()function. - Use a loop variable in a calculation inside the loop.
- Practice creating a complete, working program from scratch.
Practice Task: The "Times Table Generator"
This is a quick, practical task to solidify your skills with for loops. The goal is to create a program that generates a multiplication table for a number provided by the user.
Your Task
Write a Python program that does the following:
- Asks the user to enter a whole number.
- Uses a
forloop to iterate 12 times (from 1 to 12). - Inside the loop, it calculates the result of the user's number multiplied by the current loop number.
- Prints the full multiplication fact on each line (e.g., "7 x 1 = 7").
Example Output:
Enter a number to see its times table: 7
--------------------
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
7 x 11 = 77
7 x 12 = 84
--------------------
How to Submit (Exit Ticket)
For this activity, you will submit a single screenshot.
- Arrange your Thonny window so that your Python code is visible in the editor and the complete program output is visible in the shell below.
- Take a screenshot of the entire Thonny window.
- Submit the screenshot image file to the "Unit 3 Exit Ticket - Times Table" Assignment folder in D2L.
A Hint on `range()`
Remember that range(stop) goes up to but not including the stop number. If you want to loop from 1 to 12, what should the arguments to your range() function be? (Hint: range(1, 13))