13. Times table
Your program reads one line holding a whole number n. Print its times table: ten lines, multiplying n by 1, then
by 2, and so on up to 10.
Write each line in exactly this form: 7 x 3 = 21. That is the number, a space, a lower-case x, a space, the
multiplier, a space, =, a space, and the result. A negative n keeps its minus sign, and 0 works the same way.
Example 1
77 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 = 70Example 2
-2-2 x 1 = -2
-2 x 2 = -4
-2 x 3 = -6
-2 x 4 = -8
-2 x 5 = -10
-2 x 6 = -12
-2 x 7 = -14
-2 x 8 = -16
-2 x 9 = -18
-2 x 10 = -20Constraints
nis a whole number from -100 to 100.- Print nothing else. A prompt inside
input()is fine: the tests leave it out of the output.
Submit also runs 4 more tests you can't see.
Practises For Loops (lesson 13).
for i in range(1, 11):givesithe values 1 to 10:rangestops just before its second number.- An f-string builds each line:
f"{n} x {i} = {n * i}". - Check the spacing against the example: one space on each side of
xand of=. A negativenor 0 needs nothing extra.
Solve it without hints for 3 stars, with hints for 2, after seeing the solution for 1.
One way to solve it, once you've had a go.
Solving it after seeing the solution earns 1 star.
Your Submits show here, with their code, so you can go back to one. They stay in this browser.
# Read a whole number n and print its times table, # from "n x 1 = ..." to "n x 10 = ...". n = int(input())
Run your code to see how it does on the test cases, or Submit to check every test.