Multiple Times Tables (Using While) - Python Programming Exercise

In this exercise, you will develop a Python program that displays multiplication tables from 2 to 6 using nested "while" loops. The program will iterate through numbers from 2 to 6, displaying each multiplication table. This task will help you practice using nested loops and applying them to repetitive tasks like generating multiplication tables, which is a common problem in programming. By completing this exercise, you will enhance your ability to work with nested loops in Python and understand how to organize and control iterations for more complex tasks. This is a foundational skill for building more sophisticated programs that require multiple levels of looping and data manipulation.

 Category

Mastering Flow Control

 Exercise

Multiple Times Tables (Using While)

 Objective

Develop a Python program that displays multiplication tables from 2 to 6 using nested "while" loops.

 Example Python Exercise

 Copy Python Code
# Initialize the outer loop variable for the multiplication tables from 2 to 6
i = 2

# Use a while loop for the outer loop
while i <= 6:
    print(f"\nMultiplication table for {i}:")
    
    # Initialize the inner loop variable for the multipliers from 1 to 10
    j = 1
    
    # Use a while loop for the inner loop
    while j <= 10:
        print(f"{i} x {j} = {i * j}")
        j += 1
    
    i += 1

 Output

Multiplication table for 2:
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20

Multiplication table for 3:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30

Multiplication table for 4:
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40

Multiplication table for 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

Multiplication table for 6:
6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
6 x 10 = 60

 Share this Python Exercise

 More Python Programming Exercises of Mastering Flow Control

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Quadrilateral

    In this exercise, you will develop a Python program that prompts the user to enter a number and a width, and then displays a square of that width using ...

  •  Pause & Proceed

    In this exercise, you will develop a Python program that writes the even numbers from 10 to 20, both inclusive, except 16. The program will implement three different methods...

  •  Quadrilateral V2

    In this Python exercise, you will develop a program that prompts the user to input a number, width, and height and displays a rectangle of the specified...

  •  Iterative Patterns

    This Python program allows the user to input two numbers and displays all the numbers between them (inclusive) three times using different types of loops: "for"...

  •  Numerical Digits

    This Python program demonstrates how to calculate the number of digits in a positive integer by repeatedly dividing the number by 10. If the user enters a n...

  •  Empty Square

    This Python program prompts the user to input a symbol and a width, then displays a hollow square with the specified width. The square's outer border is...