Program Class 12 CS
Program Class 12 CS
1|Page
Program 2:- Write a python program to calculate the area of
different shapes using a while loop.
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("Please enter the correct choice")
2|Page
Output:-
Menu Driven Program
1.Area of Circle
2.Area of Rectangle
3.Area of Square
4.Exit
Enter your choice:2
Enter length of Rectangle:10
Enter breadth of Rectangle:5
Area of Rectangle: 50
Menu Driven Program
1.Area of Circle
2.Area of Rectangle
3.Area of Square
4.Exit
Enter your choice:4
3|Page
Program 3:- Nested Function
size = 5
for i in range(size):
for j in range(size):
if i == 0 or i == size - 1 or j == 0 or j == size - 1:
print('*', end='')
else:
print(' ', end='')
print()
Output:-
*****
* *
* *
* *
*****
4|Page
Program 5:- Calling function inside a function.
def f1():
s = 'I love GeeksforGeeks'
def f2():
s = 'Me too'
print(s)
f2()
print(s)
f1()
Output:-
Me too
I love GeeksforGeeks
5|Page