1
Programming fundamentals using
python
PRACTICAL FILE
SUBMITTED BY:
MUSKAN CHANDEL(1st year)
2
SNo. TOPIC SIGNATURE
1. Area of circle, rectangle, square
using if-elif-else
2. Fibonacci series
3. Pascal triangle
4. HCF of two numbers
5. LCM of two numbers
6. Program to count the number of
vowels using sets in string
7. Program to remove all the
duplicates from given string
8. Program to count all positive and
negative number in a list
9. Program to create a tuples and its
cube in each tuple
10. Program which contain user
defined function as a module to
calculate area ,volume,surface
area of cube,cuboid,square and
rectangle
11. Creating maths and statistics
modules
12.
Read a list of n integer and create
a new list
INDEX
3
Program no1. Write a python menu driven program to calculate area of
circle,rectangle,square using if-else-if statement
print("enter1 for area of circle")
print("enter2 for area of rectangle")
print("enter3 for area of square")
a=int(input(" enter your choice"))
if a==1:
r=int(input("enter the radius of circle="))
area1=3.14*r*r
print("area of cirlcle=",area1)
elif a==2:
l=int(input("enter the length of rectangle="))
b=int(input("enter the breadth of reactangle="))
area2=l*b
print("area of rectangle=",area2)
elif a==3:
s=int(input("enter the side of square="))
area3=s*s
print("arae of square=",area3)
else:
print("invalid value of a")
Output
4
Program no.2 :- write a python program to print Fibonacci
series up to a certain limit(use while)
#print fibonacci series
n=int(input("enter n:"))
a=0
b=1
c=a+b
print(a)
print(b)
while c<=n:
print(c)
a=b
b=c
c=a+b
Output
5
Program 3:-Write a program to print pascal’s triangle
#program to print pascals triangle
n=int(input("enter the no. of rows="))
k=1
for i in range(1,n+1):
for a in range(1,(n-i)+1):
print(" ",end="")
for j in range(0,i):
if j==0 or i==0:
k=1
else:
k=k*(i-j)//j
print(k, end=" ")
print()
Output
6
Program 4:- write a program to find hcf(GCD)of two numbers
num1= int(input("enter the first number\n"))
num2=int(input("enter the second number\n"))
def cal_hcf(a,b):
if b>a:
mn=a
else:
mn =b
for i in range (1,mn+1):
if ((a%i==0)and(b%i==0)):
hcf=i
return hcf
print ("The hcf of given numbers is",cal_hcf(num1,num2))
Output
7
Program 5:- write a program to find the lcm of two numbers
def compute_lcm(x, y):
# choose the greater number
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
num1 = int(input("enter the first number"))
num2 = int(input("enter the second number"))
print("The L.C.M. is", compute_lcm(num1, num2))
Output
8
Program 6:-
# Function to count vowel
def vowel_count(str):
count =0
vowel = set("aeiouAEIOU")
for alphabet in str:
if alphabet in vowel:
count = count + 1
print("No. of vowels :", count)
# Driver code
str = "hii this is muskan And i am from electronics department"
# Function Call
vowel_count(str)
Output:-
9
Program no 7:- write a program to remove all duplicates from a given
string in python
from collections import OrderedDict
def remove_duplicate(s):
return "".join(OrderedDict.fromkeys(s))
# test
s="abcfgbsca"
print(s)
print("After removing duplicates: ",remove_duplicate(s))
Output
10
Program 8:- write a program to count positive and negative numbers in lis t
list1 = [10, -21, 4, -45, 66, -93, 1]
pos_count, neg_count = 0, 0
# iterating each number in list
for num in list1:
# checking condition
if num >= 0:
pos_count += 1
else:
neg_count += 1
print("Positive numbers in the list: ", pos_count)
print("Negative numbers in the list: ", neg_count)
Output
Program :-9
11
Write a program to find the sum of elements in list
list1 = [11, 5, 17, 18, 23]
# creating sum_list function
def sumOfList(list, size):
if (size == 0):
return 0
else:
return list[size - 1] + sumOfList(list, size - 1)
# Driver code
total = sumOfList(list1, len(list1))
print("Sum of all elements in given list: ", total)
Output
12
Program no:-10 write a python program which contains user defined functions as modules to
calculate the area,perimeter ,volume and surface area of cube ,cuboid, square ,rectangle :-
def square(side):
areaS=side*side
return(areaS)
def square(a):
perimeter=4*a
return(perimeter)
def cube(b):
SAC=6*b*b
return(SAC)
def cube(A):
VC=A*A*A
return(VC)
def cubiod (l,w,h):
SACU=2*(lw+wh+lh)
return (SACU)
def cubiod(W,H,L):
VCU=W*H*L
return(VCU)
def main():
side=int(input("enter the side of square"))
u=square(side)
print("area of square",u)
a=int(input("enter the side of square(perimeter)"))
y=square(a)
print("perimeter of square",y)
b=int(input("enter the side of cube"))
Q=cube(b)
13
print("surface area of cube",Q)
A=int(input("enter the edges of cube"))
Z=cube(A)
print ("volume of cube=",Z)
l=int(input("enter the length of cubiod"))
w=int(input("enter the width of cubiod"))
h=int(input("enter the height of cubiod"))
G=cubiod(l,w,h)
print("surface area of cubiod=",G)
W=int(input("enter the WIDTH of cubiod"))
H=int(input("enter the HEIGHT of cubiod"))
L=int(input("enter the LENGTH of cubiod"))
K=cubiod(W,H,L)
print("volume of cubiod=",K)
if __name__=='__main__':
main()
Output: -
14
Program no.11 :-MATH AND STATISTICS MODULES
print("math modules")
import math
l=int(input("l="))
m=int(input("m="))
x=math.ceil(l)
print(x)
y=math.pow(l,m)
print(y)
z=math.exp(m)
print(z)
w=math.sin(l)
print(w, '\n')
print("statistics modules")
import statistics
list2=[2,5,7,8,8,8,3,9,2,1,5,3,6,7,4,8,3,9]
a=statistics.mean(list2)
print(a)
b=statistics.median(list2)
print(a)
c=statistics.mode(list2)
print(c)
d=statistics.stdev(list2)
print (d)
15
OUTPUT
16
PROGRAM:12
READ A LIST OF N INTEGERS AND CREATE A NEW LIST
n = int(input("Enter the number of elements you'd like to enter: "))
l = list()
for i in range(n):
x = int(input("Enter the element: "))
l.append(x)
print(l, "is your given list.")
pl = list()
nl = list()
for i in l:
if i > 0:
pl.append(i)
elif i < 0:
nl.append(i)
print(pl, "is the list of positive numbers.")
print(nl, "is the list of negative numbers.")
OUTPUT
17