1. Introduction
A multiplication table is a mathematical table used to define a multiplication operation for an algebraic system. It is a foundational tool used in early mathematics education, helping students learn and perform multiplication quickly. Python can easily generate and display these tables with basic loops.
2. Problem Statement
Write a Python program that takes a number as input and prints its multiplication table up to 10.
3. Solution Steps
1. Accept the input number for which the multiplication table is to be displayed.
2. Loop through numbers 1 to 10 and multiply them by the input number.
3. Format and print each line of the multiplication table.
4. Code Program
# Take the input number
num = int(input("Enter the number to find the multiplication table for: "))
# Print the multiplication table from 1 to 10
for i in range(1, 11):
# Multiply the given number by i and display the result
print(f"{num} x {i} = {num * i}")
Output:
Enter the number to find the multiplication table for: 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
Explanation:
1. num is an integer variable that stores the user input after converting it from string to integer using int(input(...)).
2. A for loop iterates through the range from 1 to 10 inclusive.
3. Inside the loop, each line of the multiplication table is printed using an f-string that inserts the current value of i and the product num * i.
4. The loop repeats this process, printing each line of the table from 1 to 10 times the input number num.
5. In the given example, the number 7 is used, and its multiplication table is printed up to 7 x 10.
Comments
Post a Comment
Leave Comment