Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C program to Generate multiplication table

Python program to Generate multiplication table

Posted on October 19, 2020October 19, 2020

Table of Contents

  • Python program to Generate multiplication table
    • Code to Generate multiplication table
      • Code to Generate multiplication table – using for loop
      • Code to Generate multiplication table – using while loop
      • Code to Generate multiplication table – using function
    • Related

Python program to Generate multiplication table

In this article, we will discuss the python program to Generate multiplication table

In this program, we are going to learn how to generate a multiplication table using 3 ways in Python language.

This is done using for loop , while loop  ,and  function

 

Code to Generate multiplication table

Code to Generate multiplication table – using for loop

In this program, we will  display multiplication table of given number using for loop in Python language.

Program 1

num=int(input("Enter an integer"))
#Take input from the user

#iterate to times from i 1 - 10
for i in range(1,11):
    print(num,'X', i,' = ',num*i)

When the above code is executed , it produces the following result

Enter an integer
9
9, X 1 =  9
9 X 2 =  18
9 X 3  =  27
9 X 4  =  36
9 X 5 =  45
9, X 6 =  54
9, X 7 =  63
9 X 8 =  72
9 X 9 =  81
9 X 10  =  90

 

  • integer variable num are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using input stream and store to the variable num
  • Create a for loop of i from 1 to 10 and increase the value of i after every iteration by 1 using range() function
  • finally, the program displays the multiplication table using print() function.

 

Code to Generate multiplication table – using while loop

In this program, we will  display multiplication table of given number using while loop in python language.

Program 2

num=int(input("Enter an integer"))
i=1
while i<=12:
    print(num,'X', i,' = ',num*i)
    i=i+1

When the above code is executed , it produces the following result

Enter an  integer

13
13 * 1 = 13
13 * 2 = 26
13 * 3 = 39
13 * 4 = 52
13 * 5 = 65
13 * 6 = 78
13 * 7 = 91
13 * 8 = 104
13 * 9 = 127
13 * 10 = 130

 

  • integer variable num are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using input stream and store to the variable num
  • Create a while loop of i from 1 to 10 and increase the value of i after every iteration by 1 using range() function
  • finally, the program displays the multiplication table using print() function.

 

Code to Generate multiplication table – using function

In this program, we will  display multiplication table of given number using function in Python language

Program 3

#Program to Generate multiplication table - using function
def multiTable(num): #function definition
  for i in range(1,11):
    print(num,'X', i,' = ',num*i)

#input a number
num=int(input("Enter an integer"))

#call the function
multiTable(num)

When the above code is executed , it produces the following result

Enter an integer15
15 X 1 = 15
15 X 2 = 30
15 X 3 = 45
15 X 4 = 60
15 X 5 = 75
15 X 6 = 90
15 X 7 = 105
15 X 8 = 120
15 X 9 = 135
15 X 10 = 150

 

Suggested post

For loop in Python

While loop in Python

Function in python

Operator in Python

Data type in Python

 

Similar post

Program to Display multiplication table in Java

Program to Display multiplication table in C

Program to Display multiplication table in C++

Program to Display multiplication table in Python

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes