CLASS XII RECORD Computer
CLASS XII RECORD Computer
f=n
for i in range(1,n):
f*=i
return f
def Power(n,m):
s1=n
for i in range(1,m):
s1*=n
return s1
m=int(input('1. x^1/2!-x^3/4!+x^5/6!.........\n 2.
x^1/3!-x^3/5!+x^5/7!-x^7/9!+...........\n'))
if m==1:
x=int(input('Enter x value:'))
y=int(input('Enter number of times to repeat:'))
s=0
for i in range(1,y+1):
s+=((-1)**(i+1))*(Power(x,(2*i-1))/Factorial(2*i))
print(s)
if m==2:
x=int(input('Enter x value:'))
y=int(input('Enter number of times to repeat:'))
s=0
for i in range(1,y+1):
s+=((-1)**(i+1))*(Power(x,(2*i-1))/Factorial(2*i+1))
print(s)
—------------------------------------------------------------------------------------------------------------------
def statistics(l):
mean=sum(l)/len(l)
count = {}
for item in l:
if item in count:
count[item] += 1
else:
count[item] = 1
max_count = max(count.values())
mode = [item for item, freq in count.items() if freq == max_count]
l.sort()
s=len(l)
k=bin(s)
if k[-1]==1:
median=l[s//2]
else:
median=(l[s//2-1]+l[(s)//2])/2
return ('mean:', mean, 'mode:',mode,'median:',median)
—------------------------------------------------------------------------------------------------------------------
def Factorial(n):
f=n
for i in range(1,n):
f*=i
return f
def fibo(n):
a,b=-1,1
l=[]
for i in range(n+1):
c=a+b
l.append(c)
a,b=b,c
l.pop()
return l
m=int(input('1. Factorial of a number\n 2. Generate ‘N’ numbers of Fibonacci series\n3.
Exit\n'))
if m==1:
n=int(input('Enter the number:'))
print(Factorial(n))
elif m==2:
n=int(input('Enter number of terms in fibonacci series:'))
print(fibo(n))
else:
exit()
—------------------------------------------------------------------------------------------------------------------
def binarys(s, n):
s.sort()
h = len(s) - 1
l=0
while l <= h:
mid = (h + l) // 2
if s[mid] == n:
return mid+1, "it's the data"
elif s[mid] < n:
l = mid + 1
else:
h = mid - 1
return -1, "data not found"
def reverse(s):
rev=''
for i in range(1,len(s)+1):
rev+=s[-i]
return rev
m=int(input('1. Binary search of an element\n2. Reverse a string\n3. Exit\n'))
if m==1:
x=eval(input('Enter list:'))
y=int(input('Enter number to be searched:'))
print(binarys(x,y))
if m==2:
k=input('Enter string:')
print(reverse(k))
else:
exit()
—------------------------------------------------------------------------------------------------------------------
def Generate(n,m,l):
k=[]
from random import randint as r
for i in range(l):
k.append(r(n,m))
return k
def Max_SecMax(k):
largest=max(k)
k.remove(largest)
slargest=max(k)
return('Largest:',largest,'Second largest:',slargest)
def Prime(k):
r=[]
for i in k:
c=0
for j in range(1,n+1):
if i%j==0:
c+=1
if c==2:
r.append(i)
if r==[]:
return 'No prime number present'
else:
return ('The prime numbers are:', r)
m=int (input('Enter lower limit:'))
n=int(input('Enter upper limit:'))
s=int(input('Enter number of elements:'))
t=Generate(m,n,s)
print(t)
print(Prime(t))
print(Max_SecMax(t))
—------------------------------------------------------------------------------------------------------------------
def vowels(t):
k=[]
b=['a','e','i','o','u']
for i in t:
r=0
for j in b:
if j in i:
r+=1
if r==5:
k.append(i)
return k
def bmi(tk):
r=()
for i in tk:
bmt=()
b=(i[1]/(i[0])**2)
bmt+=b,
if b<18.5:
bmt+='Underweight',
elif 18.5<=b<=24.9:
bmt+='Healthy Weight',
elif 25.0<=b<=29.9:
bmt+='Overweight',
else:
bmt+='Obese',
r+=bmt,
return r
m = int(input("1. Display words with all vowels\n2. Check BMI\n3. Exit\n"))
if m==1:
t=eval(input('Enter tuple containing strings:'))
print(vowels(t))
if m==2:
tk=eval(input('Enter nested tuple with tuple containing height,weight:'))
print(bmi(tk))
if m==3:
exit()
—------------------------------------------------------------------------------------------------------------------
d={}
def add_subscriber():
y='y'
while y=='y':
r=int(input('Enter the mobie number:'))
d[r]=input('Enter subscriber name:')
y=input('Do you still want to add more people (y/n):')
def modify():
h=int(input('Enter Number to be modified:'))
if h in d:
d[h]=input('Enter new subscriber name for the following number '+str(h)+':')
else:
print('No number found')
def delete():
h=int(input('Enter Number to be deleted:'))
if h in d:
del(d[h])
else:
print('No number found')
while True:
try:
r=int(input('''1.Add subscribers
2.View Directory
3.Modify a subscriber's name
4.Delete a mobile number
5.Exit
Choose any one option:'''))
if r==1:
add_subscriber()
elif r==2:
print(d)
elif r==3:
modify()
elif r==4:
delete()
elif r==5:
exit()
except KeyboardInterrupt:
print('Restart the code :)')
exit()
—------------------------------------------------------------------------------------------------------------------
nd={}
ran=['SENIORS','JUNIORS','SUBJUNIORS']
for i in ran:
temp={}
temp['BHARATHI']=int(input('Enter points of Bharathi house in the category of '+i+':'))
temp['TAGORE']=int(input('Enter points of Tagore house in the category of '+i+':'))
temp['SHIVAJI']=int(input('Enter points of Shivaji house in the category of '+i+':'))
temp['PRATAP']=int(input('Enter points of Pratap house in the category of '+i+':'))
nd[i]=temp
def MAX_SCORE(nd):
for i in nd:
k = nd[i]
r = max(k.values())
jk = [house for house, points in k.items() if points == r]
print('The most scored house in the ' + i + ' category is:', ', '.join(jk))
k=int(input('Enter 1 to view resullts:'))
if k==1:
MAX_SCORE(nd)
else:
print(nd)
exit()
—------------------------------------------------------------------------------------------------------------------
USER DEFINED MODULE:
NUMBER.py
def PALINDROME(n):
r=str(n)
if r==r[::-1]:
return(1)
else:
return(-1)
def SPECIAL(n):
z=0
r=str(n)
for i in r:
s=int(i)
for j in range(1,s):
s*=j
z+=s
if z==n:
return(1)
else:
return(-1)
PROGRAM CODE:
import NUMBER
m=int(input('''1.Check if a number is palindrom
2.Find the special numbers in a given range
Enter your choice:'''))
if m==1:
k=()
n=int(input('Enter the number of terms in the tuple:'))
for i in range(n):
r=int(input('Enter number to be added in the tuple:'))
k+=r,
c=0
for i in k:
r=NUMBER.PALINDROME(i)
if r==1:
print(i, 'is a palindrome')
c+=1
if c==0:
print('There are no pallindrome numbers in the tuple')
if m==2:
l=int(input('Number from which you want a special number:'))
h=int(input('Number till which you want a special number:'))
a=0
for i in range(l,h+1):
jk=NUMBER.SPECIAL(i)
if jk==1:
print(i,' is a special number')
a+=1
if a==0:
print('There are no special numbers within the given range')
—------------------------------------------------------------------------------------------------------------------
n='yes'
while n.lower()=='yes':
with open('REC10.txt','a+') as f:
s=input('Enter one line to be added in the file:')
f.write(s+'\n')
n=input('Do you want to add a line to your file(yes/no):')
if n.lower()=='no':
while True:
m=int(input('''1. Display number of lines
2. Copy the words containing ‘U’ into another file and display the new file
3. Convert the case of the letters(lower to upper and vice versa) in the original text
file and display the contents
4. Exit\n'''))
if m==1:
f=open('REC10.txt','r+')
print(len(f.readlines()))
f.close()
if m==2:
f=open('REC10.txt','r+')
r=f.read().split()
s=[]
for i in r:
if 'u' in i:
s.append(i)
elif 'U' in i:
s.append(i)
f.close()
k=open('mod.txt','w+')
for i in s:
k.writelines(i+'\n')
k.close()
k=open('mod.txt')
print(k.read())
k.close()
if m==3:
f=open('REC10.txt','r+')
r=f.readlines()
s=[]
for i in r:
s.append(i.swapcase())
f.close()
w=open('REC10.txt','w')
w.writelines(s)
w.close()
if m==4:
quit()
—------------------------------------------------------------------------------------------------------------------
with open('Rec11.txt','w+') as f:
n=int(input('Enter number of lines of write in the file:'))
for i in range(n):
D=input('Enter text to be added:')
f.write(D+'\n')
l='Rec11.txt'
def count(l):
f=open(l)
s=f.read()
r=s.split()
f.close()
return len(r)
def palindrome(l):
f=open(l)
s=f.read()
r=s.split()
k=[]
f.close()
for i in r:
if i==i[::-1]:
k.append(i)
return k
def dispvow(l):
f=open(l)
s=f.read()
r=s.split()
k=[]
u=['a','e','i','o','u']
f.close()
for i in r:
m=0
for j in u:
if i.lower().startswith(j):
m+=1
if m==1:
if i.lower().endswith(j):
k.append(i)
return k
while True:
menu=int(input('''
1. Count the number of words
2. Display Palindrome words
3. Display words starting and ending with a vowel
4. Exit
'''))
if menu==1:
print(count(l))
if menu==2:
print(palindrome(l))
if menu==3:
print(dispvow(l))
if menu==4:
exit()
—------------------------------------------------------------------------------------------------------------------
import pickle as p
l=[]
n=int(input('Enter number of student details to be added:'))
for i in range(n):
temp=[]
det=['Roll number','Name','Stream','Total marks']
for j in range(4):
m=input('Enter '+det[j]+':')
temp.append(m)
l.append(temp)
with open('STUDENT.bin,'wb+') as f:
p.dump(l,f)
def top():
with open('STUDENT.bin, 'rb') as f:
data = p.load(f)
stream_topper = {}
import pickle as p
def incdec():
with open('STUDENT.bin, 'rb+') as f:
data = p.load(f)
for i in data:
if i[2] == 'bio':
i[3] = str(int(i[3]) + 3)
if i[2] == 'eg':
i[3] = str(int(i[3]) - 2)
with open('STUDENT.bin, 'wb') as f:
p.dump(data, f)
with open('STUDENT.bin, 'rb') as f:
s = p.load(f)
print('The modified marks are:',s)
while True:
m=int(input('''1. Display Stream wise topper detail
2. Increment the total by 3 marks for students in the biology stream and decrement by 2for
students in EG stream.
3. Exit
'''))
if m==1:
top()
if m==2:
incdec()
if m==3:
exit()
—------------------------------------------------------------------------------------------------------------------
import pickle as p
l={}
n=int(input('Enter number of employee details to be added:'))
for i in range(n):
temp={}
temp['Name']=input('Enter employee name:')
temp['Age']=int(input('Enter employee age:'))
temp['Department']=input('Enter employee department:')
temp['Designation']=input('Enter employee designation:')
temp['Salary']=int(input('Enter employee salary:'))
l[i]=temp
with open('Employee.dat','wb+') as f:
p.dump(l,f)
def manager():
with open('Employee.dat', 'rb+') as f:
try:
r = p.load(f)
for i in r:
if r[i]['Designation'] == 'Manager':
if r[i]['Department'] in ['Finance', 'Admin']:
if r[i]['Salary'] > 50000:
print(r[i])
except EOFError:
print("The file is empty or no data to load.")
def removeret():
try:
with open('Employee.dat', 'rb+') as f:
r=p.load(f)
s=[r[i] for i in r if r[i]['Age']<=58]
k={}
for i in range(len(s)):
k[i]=s[i]
with open('Employee.dat','wb') as f:
p.dump(k,f)
with open('Employee.dat','rb') as f:
r=p.load(f)
print(r)
except EOFError:
print("The file is empty or no data to load.")
while True:
l=int(input('''1. Display details of Managers earning more than 50000 in Finance and in Admin
Dept.
2. Delete the employee details who have reached retirement age(58 years)
3. Exit
'''))
if l==1:
manager()
if l==2:
removeret()
if l==3:
exit()
—------------------------------------------------------------------------------------------------------------------
import csv
with open('GST.csv', 'a+', newline='') as f:
w = csv.writer(f)
w.writerow(['CATEGORY', 'GST_PERCENTAGE'])
w.writerows([['Automobiles', 25], ['Stationary', 12], ['Chocolates', 10], ['Dairy', 3]])
with open('ITEMS.csv', 'w+', newline='') as f:
w = csv.writer(f)
w.writerow(['ItemID', 'Name', 'Category', 'Unitprice', 'Finalprice'])
n = int(input('Enter number of rows to be added:'))
with open('ITEMS.csv', 'a+', newline='') as f:
w = csv.writer(f)
for i in range(n):
l = []
l.append(input('Enter product name:'))
l.append(input('Enter Category:'))
l.append(int(input('Enter Unitprice:')))
—------------------------------------------------------------------------------------------------------------------