Python bootcamp · Lab 07

Times table

easyFor Loops10 minLesson: For Loops

Read the question, write Python on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read n and print its times table from 1 to 10.

Each line looks like n x i = result with a single space around each symbol.

Input. One line: an integer n.

Output. Ten lines, e.g. 3 x 1 = 3 up to 3 x 10 = 30.

Constraints

  • range(1, 11) gives 1 through 10 — the 11 is excluded.

Examples

Example 1 — Exactly ten lines. The x is a lowercase letter x, not the multiply symbol.
Input
3
Output
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
Hint
  1. Loop with for i in range(1, 11):
  2. An f-string keeps the spacing tidy: f"{n} x {i} = {n * i}".
Show correct code

Peek only after you have tried. You can still Check your own version.

n = int(input())
for i in range(1, 11):
    print(f"{n} x {i} = {n * i}")
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.