Book a free demo

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

  1. range(1, 11) gives the numbers 1 to 10 (the last number is not included).
  2. for i in range(...) repeats the indented lines once for each number, with i taking each value in turn.
  3. An f-string (a string that starts with f) lets you put values inside curly brackets.
See the Python path โ†’

Try this

  • Change table to 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

All 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

For a childโ€™s class, please have a parent or guardian send the enquiry. Avoid sharing passwords or sensitive personal details.

Weโ€™ll use your details only to respond to this request.

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.

All free games โ†’
Chat on WhatsApp
Esc

Try