What You'll Learn
- •Using for loops with range()
- •Printing formatted multiplication tables
- •Allowing a configurable limit
Python
# Program to print multiplication table of a number
num = int(input("Enter a number: "))
limit = int(input("Enter limit (default 10): ") or 10)
for i in range(1, limit + 1):
print(f"{num} x {i} = {num * i}")Output
Enter a number: 5 Enter limit (default 10): 5 x 1 = 5 5 x 2 = 10 ... 5 x 10 = 50
We use a for loop with range(1, limit + 1) to generate all multipliers.
The default limit is 10, but the user can specify a different upper bound.
Each iteration prints one line of the multiplication table using an f-string.
Step-by-Step Breakdown
- 1Read the base number and limit from the user.
- 2Iterate i from 1 to limit inclusive.
- 3Compute num * i inside the loop.
- 4Print each line in a formatted way.