Board Wordformat
Board Wordformat
import math
def tarea(b,h):
a=0.5*b*h
return a
def carea(r):
a=math.pi*r*r
return a
def rarea(l,b):
a=l*b
return a
while 1:
print("Menu")
print("1.Area of triangle")
print("2.Area of circle")
print("3.Area of rectangle")
print("4.Exit")
if ch==1:
b=float(input("Enter base:"))
h=float(input("Enter height:"))
elif ch==2:
r=float(input("Enter radius:"))
elif ch==3:
l=float(input("Enter length:"))
b=float(input("Enter breadth:"))
elif ch==4:
break
else:
print("Wrong choice")
SET 2
def palindrome(s):
rev=s[::-1]
if rev==s:
else:
def countc(s,c):
c=s.count(c)
return c
while 1:
print("Menu")
print("1.Palindrome")
print("2.No.of occurance")
print("3.Exit")
if ch==1:
palindrome(s)
elif ch==2:
c=input("Enter a character:")
if len(c)==1:
else:
elif ch==3:
break
else:
print("Wrong choice")
SET 3
def fact(n):
fact=1
for i in range(1,n+1):
fact=fact*i
return fact
def fibo(n):
a=-1
b=1
for i in range(n):
c=a+b
a,b=b,c
print(c)
def sum(n):
sum=0
while n>0:
d=n%10
n=n//10
sum=sum+d
return sum
while 1:
print("Menu")
print("1.Factorial of a number")
print("2.Fibonacci series")
print("4.Exit")
if ch==1:
if n>0:
else:
elif ch==2:
fibo(n)
elif ch==3:
elif ch==4:
break
else:
print("Invalid input")
SET 4
f=open("read.txt","r")
s=f.read()
v=0
c=0
up=0
low=0
for i in s:
if i.isupper():
up=up+1
elif i.islower():
low=low+1
if i in "aeiouAEIOU":
v=v+1
c=c+1
f.close()
SET 5
f=open("read.txt","r")
d=f.readlines()
for i in d:
words=i.split()
for a in words:
print(a+"#")
f.close()
infile=open("read.txt","r")
outfile=open("read_res.txt","w")
if 'a' in line:
line=line.replace(".","")
else:
outfile.write(line)
infile.close()
outfile.close()
SET 6
R={"OM":76,"JAI":45,"BOB":89,"ALI":65,"ANU":90,"TOM":82}
def push(s,n):
s.append(n)
def pop(s):
if s!=[]:
return s.pop()
else:
return None
st=[]
for k in R:
if R[k]>=75:
push(st,k)
while True:
if st!=[]:
print(pop(st),end=" ")
else:
break
SET 7
import csv
f=open("student.csv","w",newline='')
w=csv.writer(f)
w.writerow(['Rollno','Name','Marks'])
for i in range(5):
print("Student record",(i+1))
rollno=int(input("Enter rollno:"))
name=input("Enter Name:")
marks=int(input("Enter Marks:"))
sturec=[rollno,name,marks]
w.writerow(sturec)
f.close()
SET 8
s=[]
def push():
data=[b_ID,b_NAME,b_PRICE]
s.append(data)
def pop():
if len(s)==0:
print("stack is empty")
else:
dn=s.pop()
print(dn)
def disp():
if len(s)==0:
print("stack is empty")
else:
for i in range(len(s)):
print("BOOK ID:",s[i][0])
print("BOOK NAME:",s[i][1])
print("BOOK PRICE:",s[i][2])
while True:
print('Menu')
print('1.Push')
print('2.Pop')
print('3.Display')
print('5.Exit')
if ch==1:
push()
elif ch==2:
pop()
elif ch==3:
disp()
elif ch==4:
break
else:
print("invalid choice")
SET9
import pickle
def writefile(file):
name=input("Enter name:")
age=int(input("Enter age:"))
data=[admno,name,age]
pickle.dump(data,file)
def readfile(file):
while 1:
try:
data=pickle.load(file)
print(data)
except EOFError:
return
def search(file):
flag=0
while 1:
try:
data=pickle.load(file)
if data[0]==admno:
print(data)
flag=1
return flag
except EOFError:
return flag
file=open("student.dat","ab+")
while 1:
print("Menu")
print("4.Exit")
if ch==1:
file.seek(0,0)
writefile(file)
elif ch==2:
file.seek(0,0)
readfile(file)
elif ch==3:
file.seek(0,0)
res=search(file)
if res==0:
break
else:
print("Invalid input")
file.close()
SET 10
def push(n):
stk.append(n)
top=len(stk)-1
def pop(stk):
if stk==[]:
print("underflow")
else:
def peek(stk):
if stk==[]:
print("underflow")
else:
top=len(stk)-1
def display(stk):
if stk==[]:
print("underflow")
else:
top=len(stk)-1
print(stk[top])
for i in range(top-1,-1,-1):
print(stk[i])
stk=[]
top=None
while True:
print('\t\t\t....................')
print()
print('1.Push')
print('2.Pop')
print('3.Display Stack')
print('4.Peek')
print('5.Exit')
print()
if ch==1:
push(n)
elif ch==2:
pop(stk)
elif ch==3:
display(stk)
elif ch==4:
peek(stk)
else:
break