Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Looping Statements

Print multiplication table of a given number - Python Program

Example 1 :

# Multiplication table of a given number # Using formatted strings for alignment num = int(input("Enter a number for multiplication table: ")) for i in range(1, 11): print(f"{num} x {i:2} = {num * i:3}")

Output

 
OUTPUT  :
Enter a number for multiplication table: 5
5 x  1 =   5
5 x  2 =  10
5 x  3 =  15
5 x  4 =  20
5 x  5 =  25
5 x  6 =  30
5 x  7 =  35
5 x  8 =  40
5 x  9 =  45
5 x 10 =  50 
 

Explanation

  • i:2 formats index with 2 spaces width for alignment.
  • num * i:3 aligns results in a column.
  • Runs in O(10) constant time.