Python function program to print a table of a number

In this python function program, we will create a function to print a table of a number.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function table.
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. a number to the function.
  4. Take the number (parameter) as input through the user and pass it to the function.
  5. Create a variable and assign its value equal to 0.
  6. Use a for loop to iterate over 1-10.
  7. Multiply the given number with the loop number and store the result in the created variable.
  8. Print the result after each iteration.
  9. Pass the number to the function while calling the function.
				
					def table(num):
    a = 0
    for i in range(1,11):
        a = i*num
        print(i,"*",num,"=",a)
        
n = int(input("Enter a number: "))

table(n)
				
			

Output :

				
					Enter a number: 5
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50
				
			

Related Articles

print the input string 10 times.

find the maximum of three numbers.

Leave a Comment