Skip to content
The Chat Archive
gpt-4o-mini-2024-07-18· OpenAI WildChat-4.8M (AI2)

Hello! How can i help you today?

  1. User

    Assistant: Hello! How can i help you today? User: Python Program to Display the multiplication Table Assistant:

  2. Assistant

    Certainly! Below is a simple Python program that displays the multiplication table for a given number. You can specify the number for which you want the multiplication table and also the range (for example, from 1 to 10).

    Here's a sample code:

    # Function to display the multiplication table
    def display_multiplication_table(number, limit):
        print(f"Multiplication Table for {number}")
        for i in range(1, limit + 1):
            result = number * i
            print(f"{number} x {i} = {result}")
    
    # Input for number and limit
    number = int(input("Enter the number to display its multiplication table: "))
    limit = int(input("Enter the limit for the multiplication table: "))
    
    # Display the multiplication table
    display_multiplication_table(number, limit)
    

    How it works:

    1. The program defines a function display_multiplication_table that takes two parameters: number and limit.
    2. It uses a for loop to iterate from 1 to the specified limit.
    3. For each iteration, it calculates the product of number and the current iterator i.
    4. The result is printed in a formatted manner.
    5. The program prompts the user to enter the number and the limit, and then it calls the function to display the table.

    Example Usage:

    If you input 5 as the number and 10 as the limit, the output will be:

    5 x 1 = 5
    5 x 2 = 10
    5 x 3 = 15
    ...
    5 x 10 = 50
    

    Feel free to run this code, and let me know if you have any questions or need further modifications!