Pythons Assignment
Pythons Assignment
PRACTICAL FILE
SUBMITTED BY:
2. Fibonacci series
3. Pascal triangle
12.
Read a list of n integer and create
a new list
INDEX
3
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
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()
Output
6
def cal_hcf(a,b):
if b>a:
mn=a
else:
mn =b
if ((a%i==0)and(b%i==0)):
hcf=i
return hcf
Output
7
if x > y:
greater = x
else:
greater = y
while(True):
lcm = greater
break
greater += 1
return lcm
Output
8
Program 6:-
def vowel_count(str):
count =0
vowel = set("aeiouAEIOU")
if alphabet in vowel:
count = count + 1
# Driver code
# Function Call
vowel_count(str)
Output:-
9
def remove_duplicate(s):
return "".join(OrderedDict.fromkeys(s))
# test
s="abcfgbsca"
print(s)
Output
10
Program 8:- write a program to count positive and negative numbers in lis t
pos_count, neg_count = 0, 0
# checking condition
if num >= 0:
pos_count += 1
else:
neg_count += 1
Output
Program :-9
11
if (size == 0):
return 0
else:
# Driver code
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)
SACU=2*(lw+wh+lh)
return (SACU)
def cubiod(W,H,L):
VCU=W*H*L
return(VCU)
def main():
u=square(side)
print("area of square",u)
y=square(a)
print("perimeter of square",y)
Q=cube(b)
13
Z=cube(A)
G=cubiod(l,w,h)
K=cubiod(W,H,L)
print("volume of cubiod=",K)
if __name__=='__main__':
main()
Output: -
14
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
l = list()
for i in range(n):
l.append(x)
pl = list()
nl = list()
for i in l:
if i > 0:
pl.append(i)
elif i < 0:
nl.append(i)
OUTPUT
17