A for loop over range(1, 11) gives the numbers 1 to 10. Multiply each one by the chosen number and print the line.
The program
python
n = int(input("Table of: ")) for i in range(1, 11): print(f"{n} x {i:2} = {n * i:3}")
Typed in this example: 7. Press Run to type your own.
output
Table of: 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
How it works
range(1, 11)stops before 11, soitakes the values 1 to 10.{i:2}and{n * i:3}set a width inside the f-string: the value is padded with spaces to 2 or 3 characters. This keeps the=signs and the answers in straight columns, even when the numbers have different lengths.
A full table grid
A loop inside another loop prints a grid. The outer loop picks the row, and the inner loop prints each column of that row on the same line.
python
size = 5 for row in range(1, size + 1): for col in range(1, size + 1): print(f"{row * col:4}", end="") print()
output
1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25
end="" stops print() from moving to a new line after each number. The empty print() after the inner loop ends the row.