0% found this document useful (0 votes)
5 views10 pages

Program 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

Program 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Program 1:- Write a program that generates

three 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)
seq =(a,b,c)
mean,median=stat.mean(seq),stat.median(seq)
mode=stat.mode(seq)
print("Mean =", mean)
print("Median =", median)
print("Mode =", mode)

1|Page
OUTPUT:-
Enter start: 10
Enter stop: 100
Enter step: 10
Mean = 43.333333333333336
Median = 30
Mode = 30
Program 2:- Write a python program to build
a library.
def kgtotonne( x ):
"""Return value in tonne from kilogram"""
return x * one_kg_in_tonnes
def tonnetokg( x ) :
"""Return value in kilogram from tonnes"""
return x / one_kg_in_tonnes
def kgtopound ( x ):
"""Return value pound from kilogram"""

2|Page
return x * one_kg_in_pound
def poundtokg( x ) :
"""Return value kilogram from pound"""
return x / one_kg_in_pound
one_kg_in_tonnes = 0.001
one_kg_in_pound = 2.20462
#Accessing the Library
import MassConversior as mass
print(kgtotonne(2093))
print(tonnetokg(122334))
print(kgtopound(10))
print(poundtokg(12023))
OUTPUT:-
2.093
122334000.0
22.0462
5453.547550144696

3|Page
Program 3:- Write a program to make a
function which has list or tuple used in it.
(Program that Generates a series using a function which
takes first and last values of the series and then
generates four terms that are equidistant)
def generate_series(first, last):
step = (last - first) // 3
series = [first, first + step, first + 2 * step, last]
return series
first_value = int(input("Enter first value:"))
last_value = int(input("Enter last value:"))
result_series = generate_series(first_value,
last_value)
print("Generated Series:", result_series)
OUTPUT:-
Enter first value:10
Enter last value:17
Generated Series: [10, 12, 14, 17]

4|Page
Program 4:- Write a program that generate
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:-
*****
* *
* *
* *
*****

5|Page
Program 5:- Write a program to make a
nested function.

def greeting(first, last):


def getFullName():
return first + " " + last
print("Hi, " + getFullName() + "!")
greeting('Darshan', 'Patel')
OUTPUT:-
Hi, Darshan Patel!

6|Page
Program 6:- Write a program to make a
nested function.
def f1():
s = 'I love GeeksforGeeks'
def f2():
s = 'Me too'
print(s)
f2()
print(s)
f1()
OUTPUT:-
Me too
I love GeeksforGeeks

7|Page
Program 7:- Write a program to make a
nested function.
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)
8|Page
elif choice==4:
break
else:
print("Please enter the correct choice")

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:20
Area of Rectangle: 200
Menu Driven Program
1.Area of Circle
2.Area of Rectangle
3.Area of Square
4.Exit
Enter your choice:4
9|Page
Program 8:- Write a Python program that
creates a tuple storing first 9 terms of Fibonacci
series.(Using loop function)
lst = [0,1]
a=0
b=1
c=0
for i in range(7):
c=a+b
a=b
b=c
lst.append(c)
tup = tuple(lst)
print("9 terms of Fibonacci series are:", tup)
OUTPUT:-
9 terms of Fibonacci series are: (0, 1, 1, 2, 3, 5, 8, 13, 21)

10 | P a g e

You might also like