Program 1:- Write a program that generates six random
numbers in a sequence created with (start, stop, step). Then print
the mean, median and mode of the generated numbers.
import random
import statistics as stat
start = int(input("Enter start: "))
stop = int(input("Enter stop: "))
step = int(input("Enter step: "))
a = [Link](start, stop, step)
b = [Link](start, stop, step)
c = [Link](start, stop, step)
d = [Link](start, stop, step)
e = [Link](start, stop, step)
f = [Link](start, stop, step)
seq = (a, b, c, d, e, f)
mean,median,mode = [Link](seq), [Link](seq). [Link](seq)
print("Mean =", mean)
print("Median =", median)
print("Mode =", mode)
Output:-
Enter start: 100
Enter stop: 500
Enter step: 5
Mean = 296.6666666666667
Median = 287.5
Mode = 235
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("[Link] of Circle")
print("[Link] of Rectangle")
print("[Link] of Square")
print("[Link]")
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
[Link] of Circle
[Link] of Rectangle
[Link] of Square
[Link]
Enter your choice:2
Enter length of Rectangle:10
Enter breadth of Rectangle:5
Area of Rectangle: 50
Menu Driven Program
[Link] of Circle
[Link] of Rectangle
[Link] of Square
[Link]
Enter your choice:4
3|Page
Program 3:- Nested Function
def greeting(first, last):
def getFullName():
return first + " " + last
print("Hi, " + getFullName() + "!")
greeting( 'Darshan', 'Patel')
Output:-
Hi, Darshan Patel!
Program 4:- Write a program which produces Hollow square
pattern.
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