Karan CS Project File Class 12
Karan CS Project File Class 12
Karan CS Project File Class 12
CLASS - XII A
ROLL NO. -
CONTENTS Pag
TABLE e
1. WAP to calculate and print income tax according to slab rates 2020-21. 1
2. WAP to calculate BMI of 10 students and print a report. 3
3. WAP to print a pattern of numbers. 5
4. WAP to print a pattern of Asterix. 7
5. WAP to check if a string is a palindrome or not. 9
6. WAP to create a random number generator that generates random numbers from 1 11
to 6 (simulates a dice).
7. WAP to print a Fibonacci series up to n terms. 13
8. WAP to create a dictionary with the roll number, name and marks of n students in a 15
class and display the names of students who have marks above 75.
9. WAP to check for perfect no., Armstrong no. or palindrome (using function). 18
10. WAP to implement binary search in a list. 21
11. WAP to implement user defined package ‘shapes’ with modules-area & volume. 23
12. WAP to find the no. of uppercase/lowercase characters from a given text file. 29
13. WAP to find out no. of occurrences of-a) words that begin with vowel b) a particular 31
word c) 4 letter words exist in a given text file.
14. WAP to store and display and search student data from a binary file. 34
15. WAP to create a binary file with roll number, name and marks. Input a roll number 38
and update the marks.
Create a csv file using MS-Excel with the following data:
Name, Age, Qualification, Experience, Ananya,32,PG,8
Then, write a menu driven program to perform the following operations on the file:
16. (i) Append record(s) to the file 41
(ii) Display all the data from the file
(iii) Display all the records with Age<30
(iv) Increase the Experience of all the records by 1
Delete a record with given name and age (to be input from the user).
17. WAP to implement list using stack. 47
18. WAPS to implement list using queue. 51
19. Queries Table: HOSPITAL 55
20. Queries Table: BOOKS & ISSUED 59
21. Queries Table: STORES & SUPPLIERS 63
22. WAP to create a new database & show all databases from python. 67
23. WAP to create a table in MySQL from Python. 69
24. WAP to insert records in MySQL from Python. 71
25. WAP to add new column in MySQL Table from Python. 73
26. WAP to update/ delete data in MySQL tables from Python. 75
sal=int(input("Enter your annual income:"))
tax=0
if sal<=250000:
tax=0
elif 500000>=sal>250001:
tax=0.05*sal
elif 750000>=sal>500001:
dif=sal-500000
tax=12500+(0.1*dif)
elif 100000>=sal>750001:
dif=sal-750000
tax=37500+(0.15*dif)
elif 125000>=sal>100001:
dif=sal-1000000
tax=75000+(0.2*dif)
elif 150000>=sal>125001:
dif=sal-1250000
tax=125000+(0.25*dif)
else:
dif=sal-150000
tax=187500+(0.3*dif)
d=dict()
while i>0:
n=input("Enter name:")
w=int(input("Enter weight:"))
b=w/h**2
d[n]=b
i-=1
print("Record added!")
print("*****BMI OF STUDENTS*****")
for i in d.keys():
for i in range(0,a):
for j in range(0,i+1):
print(j,end=" ")
print("\r")
a=int(input("Enter the number of lines:"))
k=2*a-2
for i in range(0,a):
for j in range(0,k):
print(end=" ")
k-=2
for j in range(0,i+1):
print(2*"* ",end="")
print("\r")
s=input(“Enter the string:”)
l=len(s)
mid=l//2
r=-1
t=1
for a in range(0,mid):
if s[a]==s[r]:
r-=1
elif(r==-1):
t=0
break
if(t==1):
print(s,"is a palindrome")
import random
while True:
if ch.upper()=="Y":
s=random.randint(1,6)
elif ch.upper()=="N":
print("Goodbye")
break
else:
print("Invalid input")
num=int(input("Enter number of terms="))
n1=0
n2=1
l=[0,1]
for i in range(2,num):
n3=n1+n2
l.append(n3)
n1=n2
n2=n3
print(l)
d={}
ans="y"
while ans=="y":
n=input("Enter name:")
m=int(input("Enter marks:"))
d[rn]=[n,m]
print("Record Added!")
print("{:<10}{:<10}{:<10}".format('ROLLNO.','NAME','MARKS'))
for i in keys():
if d[i][1]>75:
print("{:<10}{:<10}{:<10}".format(i,d[i][0],d[i][1]))
def perfect():
n=int(input("Enter any number:"))
sum1=0
for i in range(1,n):
if(n%i==0):
sum1=sum1+i
if(sum1==n):
print("The number is a perfect number!")
else:
print("The number is not a perfect number!")
def armstrong():
num=int(input("Enter a number:"))
sum=0
temp=num
while temp>0:
digit=temp%10
sum+=digit**3
temp//=10
if num==sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
def pallindrome():
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a pallindrome!")
else:
print("The number is not a pallindrome!")
print('''1)Check if number is a perfect number
2)Check if number is an armstrong number
3)Check if the number is a pallindrome''')
ch=int(input("Enter your choice;"))
if ch==1:
perfect()
elif ch==2:
armstrong()
elif ch==3:
pallindrome()
else:
print("invalid choice")
def bin_search(lst,x):
low=0
high=len(lst)-1
while low<=high:
mid=(high+low)//2
if lst[mid]<x:
low=mid+1
elif lst[mid]>x:
high=mid-1
elif lst[mid]==x:
return mid
else:
return None
a=bin_search(l,x)
if a is not None:
else:
y=0
f=open("d://Test.txt",'r')
s=f.read()
for i in s:
if i.isupper():
x+=1
elif i.islower():
y+=1
x=0
with open("d://q-12.txt","r") as f:
words=line.split()
for i in words:
for l in i[0]:
if l.lower() in ["a","e","i","o","u"]:
x+=1
def par_word():
x=0
with open("d://q-12.txt","r") as f:
words=line.split()
for i in words:
if i==c:
x+=1
print("No. of occurences of (%s) are %d"%(c,x))
def word4char():
x=0
with open("d://q-12.txt","r") as f:
for line in f.readlines():
words=line.split()
for i in words:
if len(i)==4:
x+=1
print("No. of occurences of words cotaining four letters is %d"%x)
import csv
def rcsv():
with open("d:/emp_csv","r+") as f:
csv_reader=csv.reader(f)
for r in csv_reader:
print(r)
def r30csv():
with open("d:/emp_csv.csv","r") as f:
csv_reader=csv.reader(f)
for r in csv_reader:
if r[1].isdigit():
if int(r[1])>=30:
print(r)
def acsv():
with open("emp_csv.csv","a","newline=") as f:
name=input("Enter name:")
age=int(input("Enter age:"))
qual=input("Enter the qualification:")
exp=int(input("Enter the experience:"))
a=[name,age,qual,exp]
csv.writer(f,delimiter=",").writerow(a)
def icsv():
with open("d:/emp_csv.csv","r+") as f:
csv_reader=csv.reader(f)
l=[]
for r in csv_reader:
if r[1].upper()=="AGE":
l.append(r)
else:
a=eval(r[3])
a=a+1
r[3]=a
l.append(r)
with open("d:/emp_csv.csv","w","newline=") as f:
csv.writer(f,delimiter=",").writerows(l)
def dcsv():
with open("d:/emp_csv.csv","r+") as f:
csv_reader=csv.reader(f)
l=[]
n=input("Enter name for the record you wish to delete:")
k=int(input("Enter age for the second record you want to delete:"))
for r in csv_reader:
if r[1].upper()=="AGE":
continue
if int(r[1])==k and r[0]==n.upper():
print("Deleted Record for",n)
else:
l.append(r)
with open("d://emp_csv.csv","w","newline=") as f:
csv.writer(f,delimiter=",").writerows(l)
ch=1
while ch in(1,2,3,4,5):
print('''******Employee data management******
1)Append records to file
2) Display all data
3) Display all records with age>30
4) Increase the experience of record record by
1 year 5)Delete any particular record''')
ch=int(input("Enter your Choice(1/2/3/4/5):"))
if ch==1:
d="y"
while d.upper()=="Y":
d=input("Do you want to add more records(y/n):")
acsv()
elif ch==2:
print("Records for Current Employees are:")
rcsv()
elif ch==3:
print("Records for Employees older than 30 years are:")
r30csv()
elif ch==4:
icsv()
print("Experience of all employees increaesed by 1 year!")
elif ch==5:
dcsv()
def isEmpty(S):
if len(S)==0:
return True
else:
return False
def Push(S,item):
S.append(item)
top=len(S)-1
def pop(S):
if isEmpty(S):
return "Underflow"
else:
val=S.pop(0)
if len(S)==0:
top=None
else:
top=len(S)-1
return val
def Peek(S):
if isEmpty(S):
return "Underflow"
else:
top=len(S)-1
return S[top]
def Show(S):
if isEmpty(S):
print("Sorry No items in the stack")
else:
t=len(S)-1
print("(Top)",end="")
while(t>=0):
print(S[t],"<==",end=""
) t-=1
print()
S=[]
top=None
while True:
print("**** STACK DEMONSTRATION ****")
print("1.PUSH")
print("2.POP")
print("3.PEEK")
print("4.SHOW STACK")
print("0.EXIT")
return False
def Enqueue(Q,item):
Q.append(item)
if len(Q)==1:
front=rear=0
else:
rear=len(Q)-1
def Dequeue(Q):
if isEmpty(Q):
return"Underflow"
else:
val=Q.pop(0)
if len(Q)==0:
front=rear=None
return val
def Peek(Q):
if isEmpty(Q):
return"Underflow"
else:
front=0
return Q[front]
def Show(Q):
if isEmpty(Q):
m=c.connect(host="localhost",user="root",passwd="jas@1699")
mc=m.cursor()
print("Database Created!")
mc.execute("Show Databases")
for x in mc:
print(x)
import mysql.connector as sql
mydb=sql.connect(host="localhost",user="root",passwd="jas@1699",database="school")
mc=mydb.cursor()
print("Table created!")
import mysql.connector as sql
db=sql.connect(host="localhost",\
user="root",\
passwd="jas@1699",\
database="school")
mycr=db.cursor()
print("Record(s) Added!")
import mysql.connector as sql
db=sql.connect(host="localhost",\
user="root",\
passwd="jas@1699",\
database="school")
mycr=db.cursor()
print("Column(s) added")
import mysql.connector as sql
db=sql.connect(host="localhost",\
user="root",\
passwd="jas@1699",\
database="school")
mycr=db.cursor()
def delete():
nm=input("Enter name of the student whose record is to be deleted:")
try:
query="Delete from students where Name='%s'"%nm
mycr.execute(query)
db.commit()
print(mycr.rowcount,"record(s) deleted")
except:
db.rollback()
print("Error,record not found")
def update():
a=input("Enter the name:")
m=int(input("Enter new marks:"))
try:
query="Update students set marks=%d where name='%s'"%(m,a)
mycr.execute(query)
db.commit()
print(mycr.rowcount,"record(s) updated")
except:
db.rollback()
print("Error in connection")
ch=1
print('''1)Delete a record
2)Update marks''')
ch=int(input("Enter your choice:"))
if ch==1:
delete()
elif ch==2:
update()
else:
print("Invalid input")
db.close()