0% found this document useful (0 votes)
7 views

Program Class 12 CS

The document contains 5 programs: 1) generates random numbers and calculates statistics, 2) calculates area of shapes in a loop, 3) demonstrates nested functions, 4) prints a hollow square pattern, 5) calls a function inside another function and prints variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Program Class 12 CS

The document contains 5 programs: 1) generates random numbers and calculates statistics, 2) calculates area of shapes in a loop, 3) demonstrates nested functions, 4) prints a hollow square pattern, 5) calls a function inside another function and prints variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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 = random.randrange(start, stop, step)
b = random.randrange(start, stop, step)
c = random.randrange(start, stop, step)
d = random.randrange(start, stop, step)
e = random.randrange(start, stop, step)
f = random.randrange(start, stop, step)
seq = (a, b, c, d, e, f)
mean,median,mode = stat.mean(seq), stat.median(seq). stat.mode(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("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

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

You might also like