gpt-4o-mini-2024-07-18· OpenAI WildChat-4.8M (AI2)
Hello! How can i help you today?
- User
Assistant: Hello! How can i help you today? User: Python Program to Display the multiplication Table Assistant:
- 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:
- The program defines a function
display_multiplication_tablethat takes two parameters:numberandlimit. - It uses a
forloop to iterate from 1 to the specified limit. - For each iteration, it calculates the product of
numberand the current iteratori. - The result is printed in a formatted manner.
- 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
5as the number and10as the limit, the output will be:5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 ... 5 x 10 = 50Feel free to run this code, and let me know if you have any questions or need further modifications!
- The program defines a function