Menu driven Program in Python using while loop

We will make a menu-driven program in python to calculate the area of different shapes using a while loop and calculator also.
A menu driven program in python is a program that obtains a choice from a user by displaying the menu. Then, it will perform some operations and print the result according to the user's choice.

If you are looking for menu driven program for a calculator Click Here


Table of Contents

Menu Driven Program in Python using while loop

A menu-driven program to find the area of a circle, square, and rectangle in python.
In this post we will make a menu-driven program using a while loop and simple if-else statements for the following operations:
  1. Area of Circle
  2. Area of Rectangle
  3. Area of square
  4. Exit
while True:
    print("Menu Driven Program")
    print("1.Area of Circle")
    print("2.Area of Rectangle")
    print("3.Area of Square")    
    print("4.Exit")
    choice=int(input("Enter your choice:"))
    if choice==1:
        radius=int(input("Enter radius of Circle:"))
        print("Area of Circle",3.14*radius*radius)
    
    elif choice==2:
        length=int(input("Enter length of Rectangle:"))
        breadth=int(input("Enter breadth of Rectangle:"))
        print("Area of Rectangle:",length*breadth)
    
    elif choice==3:
        side=int(input("Enter side of Square:"))
        print("Area:",side*side)
    elif choice==4:
        break
    else:
        print("Wrong Choice")
    repeat=input("Do you want to continue? (y/n)")
    if repeat=='n'or repeat=='N':
        break
        
Output:

Menu Driven Program
1. Area of Circle
2. Area of Rectangle
3. Area of Square
4. Exit
Enter your choice:3
Enter the side of Square:5
Area: 25

Quick algorithm:
  • Print the menu on the screen.
  • Input the choice from the user.
  • According to their choice, display the area using the if-else statement.

menu driven program in python using while loop
If you cannot run this program or get an error, let me know in the comment section. You can also message us on our Instagram account. We will send you a meet link and teach you every line of code free of cost.
Related posts:

Menu Driven Program for Class 12th Students [CBSE BOARD]

We will make a program that helps us calculate the area of shapes according to the user's choice. The user will decide whether he wants to get the area of a square or a circle, depending on his/her choice. 

We will make this program using an infinite while loop which will terminate as soon as users choose the option to exit. We will store his choice in a variable, which tells us about his choice so that we can make our if-else statements.Then we ensure that we cover all the conditions that our menu provides. However, there will be another case when the user provides input which is not available in our menu. 
For example, you go to Domino and order momos which is unavailable on their menu. So, they will tell you "Wrong choice" and order something else shown on their menu. Hence we will add an else statement that will print the wrong choice. 

Video Solution

Menu Driven Program in Python using functions

In this program, we will create a python program for class 12 in which we will calculate the area of different shapes like circles, squares, and rectangles using functions.

def circle(radius):
    print("Area of Circle",3.14*radius*radius)

def rectangle(length,breadth):
    print("Area of Rectangle:",length*breadth)
    
def square(side):
    print("Area:",side*side)

while True:
    print("Menu Driven Program")
    print("1.Area of Circle")
    print("2.Area of Rectangle")
    print("3.Area of Square")    
    print("4.Exit")
    choice=int(input("Enter your choice:"))


    if choice==1:
        radius=int(input("Enter radius of Circle:"))
        circle(radius)


    elif choice==2:
        length=int(input("Enter length of Rectangle:"))
        breadth=int(input("Enter breadth of Rectangle:"))
        rectangle(length,breadth)
    
    elif choice==3:
        side=int(input("Enter side of Square:"))
        square(side)


    elif choice==4:
        break
    else:
        print("Wrong Choice")
Output:

Enter your choice:1
Enter radius of Circle:5
Area of Circle 78.5

This Menu-driven program in python using functions is essential for class 12th students. One question about this program can come from the CBSE board, so prepare well for it. If you have any doubt, let me know in the comment section.
We can also call this program a python menu loop because we will display the menu in a loop until the user wants to exit.

Questions Related to this Program

Explain a menu-driven program with an example?
Menu-driven program using if-else, which will perform operations according to the user's choice. Here are examples of menu-driven programs.

  1. Menu-driven program to calculate the area/perimeter of different shapes.
  2. Menu-driven program to perform simple arithmetic operations (create a simple calculator) like adding two numbers in python and subtraction.

How do you exit a menu-driven program?
We have to use the break statement to exit from the loop. When users want to leave the loop, They will choose the option to exit, and in that "if condition," we will write a break statement.


Related post:
Python Program to Check Armstrong Number
Simple Python Program to Print Hello world
Python program to check even or odd

About this program: This is a menu-driven program in python using a while loop and functions. It is an essential menu-driven program for board practicals. You can comment below if you have any queries related to this post.

Please subscribe to our newsletter to connect with us. If you like this post, then please share this post with your friends.

15 comments

  1. how can we make the loop run again to accept the input if input is "Wrong Choice"
    while True:
    dine=eval(input("Please type 1 for Drive-Thru ; 2 for Dine-in ; 3 for Carry-out/Delivery"))

    if dine==1:
    dine_type="Drive-Thru"

    elif dine==2:
    dine_type="Dine-in"

    elif dine==3:
    dine_type="Carry-out/Delivery"
    else:
    print("Wrong Choice")
  2. is def compulsary for structure progamming?
    1. No, it's not compulsory to use functions for structure programming.

      We break complex programs into small tasks using functions.

      To organize our programs in python we use functions.
  3. Develop menu driven program for library book management without using def function
    1. Ok
  4. Very informative and educative site
    1. Thanks 😊
  5. What will be the flowchart for the above program?
    1. We will be uploading it soon. Please text us on instagram for the same.
  6. Great website
    1. Thanks ❤️
  7. Thanks for this post, great content.
  8. Welcome, please fill our feedback form
  9. I have an assignment
Please do not enter any spam link in the comment box.