Karan CS Project File Class 12

Download as pdf or txt
Download as pdf or txt
You are on page 1of 82

COMPUTER SCIENCE FILE

NAME - karan wadhwa

SCHOOL - JYOTI MODEL SR. SEC. SCHOOL

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)

print ("Your income tax is:",tax)


i=10

d=dict()

while i>0:

n=input("Enter name:")

w=int(input("Enter weight:"))

h=float(input("Enter height in m:"))

b=w/h**2

d[n]=b

i-=1

print("Record added!")

print("*****BMI OF STUDENTS*****")

print ("{:<10} {:<10} ".format( 'NAME','BMI'))

for i in d.keys():

print ("{:<10} {:<10} ".format(i,d[i]))


a=int(input("Enter the number of lines:"))

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):

print(s,"is not a palindrome")

t=0

break

if(t==1):

print(s,"is a palindrome")
import random

while True:

ch=input("Do you wish to cast the die(y,n):")

if ch.upper()=="Y":

s=random.randint(1,6)

print("You rolled %d"%s)

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":

rn=int(input("Enter roll number:"))

n=input("Enter name:")

m=int(input("Enter marks:"))

d[rn]=[n,m]

print("Record Added!")

ans=input("Do you wish to continue(y,n):")

print("*****STUDENTS WHO SCORED MORE THAN 75*****")

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

l=eval(input("Enter the list:"))

x=int(input("Enter the number to search:"))

a=bin_search(l,x)

if a is not None:

print("%d is present at index %d"%(x,a))

else:

print("%d is not present in the list"%x)


from Shapes import vol_module as V,area_module as A
ch=1
while ch>0 and ch<=8:
print("1)Volume of cube")
print("2)Volume of cuboid")
print("3)Volume of cone")
print("4)Volume of cylinder")
print("5)Area of square")
print("6)Area of rectangle")
print("7)Area of circle ")
print("8)Area of triangle")
ch=int(input("Enter your choice:"))
if ch==1:
s=int(input("Enter the side:"))
v=V.vol_cube(s)
print("Volume of cube=",v)
elif ch==2:
l=int(input("Enter the length:"))
b=int(input("Enter the breadth:"))
h=int(input("Enter the height:"))
v=V.vol_cuboid(l,b,h)
print("Volume of cuboid=",v)
elif ch==3:
r=int(input("Enter the radius:"))
h=int(input("Enter the
height:")) v=V.vol_cone(r,h)
print("Volume of cone=",v)
elif ch==4:
r=int(input("Enter the radius:"))
h=int(input("Enter the height:"))
v=V.vol_cylinder(r,h)
print("Volume of cylinder=",v)
elif ch==5:
s=int(input("Enter the side:"))
a=A.square_ar(s)
print("Area of square=",a)
elif ch==6:
l=int(input("Enter the length:"))
b=int(input("Enter the breadth:"))
a=A.rect_ar(l,b)
print("Area of rectangle=",a)
elif ch==7:
r=int(input("Enter the radius:"))
a=A.circle_ar(r)
print("Area of circle=",a)
elif ch==8:
b=int(input("Enter the base:"))
h=int(input("Enter the
height:")) a=A.triangle_ar(b,h)
print("Area of triangle=",a)
else:
print("Invalid Choice")
x=0

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

print("Count of occurenece of upper case letters is:",x)

print("Count of occurenece of lower case letters is:",y)


def vowel():

x=0

with open("d://q-12.txt","r") as f:

for line in f.readlines():

words=line.split()

for i in words:

for l in i[0]:

if l.lower() in ["a","e","i","o","u"]:

x+=1

print("No. of occurences of words starting is %d"%x)

def par_word():

c=input("Enter the word:")

x=0

with open("d://q-12.txt","r") as f:

for line in f.readlines():

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)

print('''1)To display number of words starting with vowels


2)To display number of time a particular word has appeared
3)To display number of times a 4-letter word has appeared''')
ch=int(input("Enter your choice:"))
if ch==1:
vowel()
elif ch==2:
par_word()
elif ch==3:
word4char()
import pickle
def datastore():
with open("student.dat","ab+") as f:
ans='y'
x={}
y=0
while ans.upper()=='Y':
rollno=int(input("Enter rollno:"))
name=input("Enter name:")
age=int(input("Enter age:"))
section=input("Enter section:")
marks=int(input("Enter marks:"))
ans=input("Do you wish to add more records(y,n):")
x[rollno]=['Name:',name,'Age:',age,'Section:',section,'Marks',marks]
print("")
y+=1
pickle.dump(x,f)
print("%d record(s) have been added to the file"%y)
def datadisplay():
y=[]
with open("student.dat","rb") as f:
y=pickle.load(f)
for i in y:
print(i,":",y[i],"")
def datasearch():
y=[]
with open("student.dat","rb") as f:
y=pickle.load(f)
a=int(input("Enter the admission number you wish to search for:"))
for i in y:
if i==a:
print("RECORD:",i,y[i])
break
else:
continue
else:
print("Record not found")
c='y'
while c.upper()=="Y":
print('''******Student Database Management******
1)Write Records into file
2) Display all records
3) Search for particular
records''') ch=int(input("Enter
your choice:")) if ch==1:
datastore()
elif ch==2:
datadisplay()
elif ch==3:
datasearch()
else:
print("INVALID INPUT")
c=input("Do you wish to continue(y,n):")
import pickle
def datastore():
with open("d://students.dat","ab+") as f:
ans="y"
x={}
y=0
while ans.upper()=="Y":
rollno=int(input("Enter rollno:"))
name=input("Enter name:")
marks=int(input("Enter marks:"))
ans=input("Do you wish to add more records(y,n):")
x[rollno]=['Name:',name,'Marks',marks]
print("")
y+=1
pickle.dump(x,f)
print("%d record(s) have been added to the file"%y)
def update():
s={}
found=1
rollno=int(input("Enter the roll no. whose marks you wish to update:"))
with open("d://students.dat","rb+") as file:
try:
while True:
pos=file.tell()
s=pickle.load(file)
for i in s.keys():
if i==rollno:
marks=int(input("Enter marks:"))
s[i][3]=0
found=0
file.seek(pos)
pickle.dump(s,file)
except EOFError:
if found==1:
print("Roll number not found")
else:
print("Marks updated!")
c="y"
while c.upper()=="Y":
print('''******Student Database Management******
1)Write records into file
2) To update marks of
student''') ch=int(input("Enter
your choice:")) if ch==1:
datastore()
elif ch==2:
update()
else:
print("INVALID INPUT")
c=input("Do you wish to continue(y,n):")
Q-16) 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:
(i) Append record(s) to the file
(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
(v) Delete a record with given name
and age (to be input from the user).

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")

ch=int(input("Enter your choice:"))


if ch==1:
n=int(input("Enter the number of items you wish to push:"))
for a in range(n):
val=input("Enter item to push:")
Push(S,val)
elif ch==2:
val=pop(S)
if val=="Underflow":
print("Stack is Empty")
else:
print("Deleted item was:",val)
elif ch==3:
val=Peek(S)
if val=="Underflow":
print("Stack is Empty")
else:
print("Top Item:",val)
elif ch==4:
Show(S)
elif ch==0:
print("Bye")
break
def isEmpty(Q):
if len(Q)==0:
return True
else:

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):

print("Sorry No items in the queue")


else:
t=len(Q)-1
print("(Front)",end="")
front=0
i=front
rear=len(Q)-1
while(i<=rear)
:
print(Q[i],"<==",end="")
i+=1
print()
Q=[]
front=rear=None
while True:
print("**** QUEUE DEMONSTRATION ****")
print("1.ENQUEUE")
print("2.DEQUEUE")
print("3.PEEK")
print("4.SHOW QUEUE")
print("0.EXIT")
ch=int(input("Enter your choice:"))
if ch==1:
n=int(input("Enter the number of items you wish to insert:"))
for a in range(n):
val=input("Enter item to insert:")
Enqueue(Q,val)
elif ch==2:
val=Dequeue(Q)
if val=="Underflow":
print("Queue Empty")
else:
print("Item deleted:",val)
elif ch==3:
val=Peek(Q)
if val=="Underflow":
print("Queue Empty")
else:
print("Top Item:",val)
elif ch==4:
Show(Q)
elif ch==0:
print("Bye")
break
● To create the table hospital and see its description

● To insert values into the table

● To select all information of patients of cardiology department


● To list names of patients who are in ENT

● To list names of all patients with their date of admission in


ascending order

● To display patient’s name, charges, age for only female patients


● To count the number of patients with age>30

● To insert a new row in the HOSPITAL table with the following


data:
11,”Aftab”,24,”Surgery”,{25/02/98},300,”M”

● Give outputs for the following SQL statements


1. Select Count(Distinct charges) from hospital;
2. Select Min(age) from hospital where gender=’F’;
3. Select Sum(charges) from hospital where
department=’ENT’;
4. Select Avg(charges) from hospital where gender=’M’
● To create the table books

● To insert data into the table books

● To create table issued

● To insert values into table issued

● To show Book name, Author name and price of books of EBP


publishers
● To list the names of the books of fiction type

● To display the names and price of the books in descending


order of their price

● To increase the price of all books of First Publ. by 50

● To display the Book_Id, Book_Name and Quantity_Issued for all


books which have been issued
● To insert a new row into the table issued having the following
data:”F0002”,4

● Give the output of the following queries based on the above


tables:
1. Select count(Distinct Publishers) from Books;

2. Select Sum(Price) from Books where Quantity>5

3. Select count(*) from books


● To create the table STORE

● To insert values into table store

● To create the table Suppliers


● To insert values into the table suppliers

● To display details of all items in the store table in ascending order


of LastBuy
● To display ItemNo and item name of those items from store
whose Tate is higher than 15 rupees

● To display details of those items whose Scode is 22 or Qty is


more than 110 from table store

● To display minimum rate of the items for each supplier


individually as per Scode from the table Store
● Give the outputs of the following SQL queries:
1. Select count(Distinct Scode) from store;
2. Select Rate*Qty from store where itemNo=2004;
3. Select Item, Sname from Store S, Suppliers P
import mysql.connector as c

m=c.connect(host="localhost",user="root",passwd="jas@1699")

mc=m.cursor()

mc.execute("Create database abc")

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()

mc.execute("CREATE TABLE STUDENTS(RollNo int(3) primary key,Name varchar(30) NOT


NULL,Age int(2),Marks int(3),Dateofbirth Date)")

print("Table created!")
import mysql.connector as sql

db=sql.connect(host="localhost",\

user="root",\

passwd="jas@1699",\

database="school")

mycr=db.cursor()

mycr.execute("INSERT into STUDENTS values(1,'Jayaditya',17,452,'2003-01-05')")


db.commit()

print("Record(s) Added!")
import mysql.connector as sql

db=sql.connect(host="localhost",\

user="root",\

passwd="jas@1699",\

database="school")

mycr=db.cursor()

mycr.execute("alter table STUDENTS add DOB date")

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()

You might also like