Beginner ยท ages 8+ ยท for loop ยท range ยท f-strings
Times table printer in Python.
Print the seven times table with a loop.
The program
Press Run to see what it prints. Change anything you like, then run it again.
table = 7
for i in range(1, 11):
print(f"{i} x {table} = {i * table}")1 x 7 = 7 2 x 7 = 14 3 x 7 = 21 4 x 7 = 28 5 x 7 = 35 6 x 7 = 42 7 x 7 = 49 8 x 7 = 56 9 x 7 = 63 10 x 7 = 70
How it works
range(1, 11)gives the numbers 1 to 10 (the last number is not included).for i in range(...)repeats the indented lines once for each number, withitaking each value in turn.- An f-string (a string that starts with
f) lets you put values inside curly brackets.
Try this
- Change
tableto 12. - Make it print the table up to 12 times.
- Print the table backwards by using
range(10, 0, -1).
Stuck on an error? Read how to debug Python.
Similar ideas
More programs
FAQ
Times table printer: questions
What does the times table printer program do?
Print the seven times table with a loop. It prints: 1 x 7 = 7 / 2 x 7 = 14 / 3 x 7 = 21 โฆ
Which Python ideas does it use?
for loop, range, f-strings. Beginner level, suitable from about age 8.
How do I run it?
Press Run on this page. To run it on your own computer, install Python 3 and save the code in a file ending in .py. It prints the same thing.
What should I try next?
Change table to 12. Make it print the table up to 12 times. Print the table backwards by using range(10, 0, -1).
Start a conversation
Want a teacher to guide the learning?
Tell us the learner's age and what they can already do, and we will suggest a starting point. A parent or guardian can make the enquiry.
- Tell us the learnerโs age or grade and goals
- Weโll suggest a suitable class or learning path
- Weโll confirm format, timing and fees with a parent or guardian
Play it, don't just read it
Write some code right now
Free games that need no sign-up. Pick one and play for five minutes.
Pick a game
- Bug HunterA Python program prints the wrong answer. Find the one line with theโฆPlay
- Code BuilderThe lines of a Python program are mixed up. Tap them into the rightโฆPlay
- Predict the OutputRead a short Python program and choose what it prints. Then watch it runโฆPlay
- Code JungleWrite real Python to guide Miko the monkey to every banana. 24 levels:โฆPlay