The provided Python program is designed to display the multiplication table for a specified number up to a given limit. It begins by prompting the user to enter a number for which they want to generate the multiplication table. Subsequently, the program requests the user to input the number of times they wish to display in the table. The core functionality is encapsulated in the multiplication_table function, which takes the user-provided number and the specified limit as parameters. Inside the function, a loop iterates from 1 to the specified limit, calculating the product of the input number and the current iteration. The result is then printed in a formatted manner, showing the multiplication table entries. Users can interact with the program by entering their desired number and the limit, and the program will output the corresponding multiplication table.
Source code
def multiplication_table(number, n):
print(f"Multiplication Table for {number} up to {n} times:")
for i in range(1, n+1):
result = number * i
print(f"{number} x {i} = {result}")
# Input the number for which you want to display the multiplication table
num = int(input("Enter a number: "))
# Input the number of times you want to display the multiplication table
times = int(input("Enter the number of times: "))
# Call the function to display the multiplication table
multiplication_table(num, times)
Description
Certainly! Let’s break down the provided Python program step by step:
- Function Definition:
def multiplication_table(number, n):Here, a function namedmultiplication_tableis defined, which takes two parameters:number(the base number for the multiplication table) andn(the number of times the table should be displayed). - Print Statement:
print(f"Multiplication Table for {number} up to {n} times:")This line prints a descriptive message indicating which multiplication table is being displayed, based on the user input fornumberandn. - For Loop:
for i in range(1, n+1):This line initiates aforloop that iterates over the range from 1 ton+1. The loop variableirepresents the current iteration. - Multiplication Calculation:
result = number * iInside the loop, the program calculates the product of thenumberand the current value ofito get each entry in the multiplication table. - Print Multiplication Table Entry:
print(f"{number} x {i} = {result}")This line prints each multiplication table entry in a formatted manner, showing the multiplication operation and the result. - User Input:
num = int(input("Enter a number: ")) times = int(input("Enter the number of times: "))The program prompts the user to input the base number (num) for the multiplication table and the number of times (times) they want the table to be displayed. - Function Call:
python multiplication_table(num, times)
Finally, the program calls themultiplication_tablefunction with the user-provided values fornumandtimes, executing the logic within the function to display the multiplication table.
Users can run this program, input the desired values when prompted, and observe the multiplication table for the specified number up to the specified limit.
Screenshot

