Professional Documents
Culture Documents
Computer
Computer
Computer
CHHATARPUR
Session : 2022-23
Computer Science
Project File
Date :
Principal’ s Signature
ACKNOWLEDGEMENT
import math
print("For quadratic equation ax^2+bx+c=0, enter coefficients")
a= int(input("Enter a value for coefficient a: "))
b= int(input("Enter value for coefficient b : "))
c= int(input("Enter a value of constant c :"))
if a ==0:
print("Value of",a,"should not be zero")
print("Aborting!")
else :
delta= b*b-4*a*c
if delta > 0:
root1 = (-b+math.sqrt(delta))/(2*a)
root2 = (-b-math.sqrt(delta))/(2*a)
print("Roots are real and unequal")
print("Root=1",root1,"Root2",root2)
elif delta ==0:
root3=(-b+math.sqrt(delta))/(2*a)
print("Roots are real and equal")
print("roots=",root3,root3)
else:
print("Roots are complex and imaginary")
Output
Output
Output
Positional Argument
-100 100
Default Argument
-100 90
Keyword Argument
The youngest child is: Amar
Variable Length Argument
(2,3,4) (1,2)
Program-4
Demonstration of scope of variable [LEGB] rule
import math
p=5
def sum(q,r=2):
global p
p=r+q**2
return p
a,b=10,5
print('First function call sum(a,b):',sum(a,b))
print('First function call sum(r=5,q=1):',sum(r=5,q=1))
print("The value of Pi",math.pi) #Extended scope
Output
../
Geometry Package
area.py
vol.py
__init__.py
Shape.py
area.py
def Cir(r):
'''Function for area of circle'''
print(__name__)#print current module name
return 3.14*r*r
def Rect(a,b):
return a*b
vol.py
def cuboid(l,b,h):
print(__name__)#print current module name
return l*b*h
Shape.py
from geometry import area,vol
print(area.Cir(10)) # 314.0
print(help(area.Cir)) # function for area of circle
# print the doc string of function
print(area.Rect(10,20))
#200
print(vol.cuboid(10,20,5)) #10000
print(__name__) #print current module name
Output
3.14.0,200,1000
Program-6
Count number of lines in a text file
f=open("a.txt",'r')
line_count=0
for line in f:
line_count+=1
print("The number of lines in a.txt is:", line_count)
Output
Output
Output
0
Welcome
7
To Care English School
Regularly attend CS classes
54
O Ca
Program-9
Finding a character in a file and write it to another
file
file_inp=open('input.txt','r+')
for line in file_inp:
if 'a' in line:
file_out=open("output.txt",'a+')
file_out.write(line)
file_out.close( )
file_inp.close( )
Output
Program-10
Stack Implementation using list
def isEmpty(stk):
if stk==[]:
return True
else:
return False
def Push(stk,item):
stk.append(item)
top=len(stk)-1
def Pop(stk):
if isEmpty(stk):
return "Underflow"
else:
item=stk.pop()
if len(stk)==0:
Top=None
else:
top=len(stk)-1
return item
def Display(stk):
if isEmpty(stk):
print("Stack Empty")
else:
top=len(stk)-1
print(stk[top],"<--top")
for a in range(top-1,-1,-1):
print(stk[a])
#___main()____
Stack=[]
top=None
while True:
print("---Stack Operations---")
print("1. Push","2. Pop", "3. Display","4. Exit")
ch= int(input("Enter your choice(1-5):"))
if ch==1:
item=int(input("Enter item: "))
Push(Stack,item)
elif ch==2:
item=Pop(Stack)
if item=="Underflow":
print("Underflow :stack is empty")
else:
print("Popped item is",item)
elif ch==3:
Display(Stack)
elif ch==4:
break
else:
print("Please enter the correct number in range(1-5)")
Output
Program-11
SQL queries
1. show database;
use xiia23;
DEPARTMENT varchar(5),
CITY varchar(12));
Output
0 rows affected
3. describe DEPT;
Output
DEPT(DCODE));
Output
0 rows affected
5. describe WORKER;
Output
Output
5 rows affected
Output
Output
5 rows affected
Output
10. Display all the details of the workers working in D01 Department
Output
Output
12. Display the workers name containing substring ‘ha’
Output
13. Display the details of the workers having birthday after 01.07.1990
Output
14. Display the details of the workers who have joined after 01.01.2013
and before 01.01.2014
select * from WORKER where DOJ between ‘2013-01-01’ and
‘2014-01-01’;
Output
Output
16. Display the names and worker number of the workers who live in
delhi
select NAME,WNO from WORKER W,DEPT D where W.DCODE=D>DCODE
and D.CITY=’Delhi’;
Output
Output
Program-12
SQL queries
1. show databases;
use xiia23;
Title varchar(30),
type varchar(30),
Rating varchar(15),
stars varchar(10),
qty int,
price float(10)
);
Output:
0 rows affected
3. describe movie;
Output:
4. insert into movie values
(3,"top gun","drama","PG","cruise",7,49.95),
(4,"splash","comedy","PG13","hanks",3,29.95),
(7,"cocoon ","scifi","PG","amecho",2,31.95),
(10,"tootsie ","comedy","PG","hoffman",1,29.95);
Output:
10 rows affected
5. Display a list of all movies with price over 20 & sorted by price
Output:
Output:
7. Display a report using a movie number ,current value &
replacement value for each movie in the above table calculate the
replacement value for all movies as QTY*price*1.15
Select no, qty*price*1.15 as replacement_value from movie;
Output:
Output:
Output:
Program-13
SQL queries
1. show databases;
use xiia23;
mgr integer(5),
hiredate date,
sal decimal(6,2),
comm decimal(6,2),
deptno int(3)
);
Output:
0 rows affected
describe employee;
Output
4. Insert the values into table
( 7369,'Smith','clerk',7902,'1980-12-17',800,NULL,20),
(7499,'Allen','salesman',7698,'1981-02-20',1600,300,30),
(7521,'Ward','salesman',7698,'1981-02-22',1250,500,30),
(7566,'Jones','manager',7839,'1981-04-02',2975,NULL,20),
(7654,'Martin','salesman',7698,'1981-09-28',1250,1400,30),
(7698,'Black','manager',7839,'1981-05-01',2850,NULL,30),
(7782,'Clark','manager',7839,'1981-06-09',2450,NULL,10),
(7788,'Scott','analyst',7566,'1981-04-19',3000,NULL,20),
29(7839,'King','precedent', NULL,'1981-11-09',5000,NULL,10),
(7844,'Turner','salesman',7688,'1981-09-08',1500,0,30),
(7876,'Adams','clerk',7788,'1987-05-23',1100,null,20),
(7900,'James','clerk',7698,'1981-12-03',950,null,30),
(7920,'Ford','analyst',7566,'1981-12-03',3000,null,20),
(7934,'Miller','clerk',7782,'1982-01-23',1300,null,10);
Output
14 rows affected
Output
Output
7. Display job wise salary sum min max average and count from
employee table
SELECT job,SUM(sal),AVG(sal),MAX(sal), COUNT(*) as employee_count
FROM employee group by job;
Output
Output
Output
Output
Program-14
SQL queries
1. show databases;
use xiia23;
dcode integer(5),
qty integer(5),
unitprice decimal(5,2),
stockdate date
);
Output
0 rows affected
(5001,'Eraser Small',102,210,5,'2018-03-11'),
(5006,'Eraser Big',102,60,10,'2017-11-18'),
(5007,'Sharpener Classic',NULL,160,8,'2017-06-12');
Output
7 rows affected
4. Select all record of table
Select * from item;
Output
Output
Output
7. Select Item name of those items which are quantity between 100-
200
select * from item where qty between 100 and 200;
Output
8. Select all record of Items which contains pen word in it
select * from item where item like '%pen%';
Output
Output
Output
11. Display all items which are stocked in the month of March
select * from item where stockdate like '%03%';
Output
Output
1 row affected
Output
8 rows affected
Output
Output
Program-15
SQL queries
1. show database;
use xiia23;
name varchar(15),
stipend float(30),
stream varchar(15),
avgmark float(10),
grade char(3),
class varchar(3));
Output
0 rows affected
3. describe student1;
Output
4. Display all student details
Output
Output
select Name from student1 where class like “12_” order by\
stipend;
Output
Output
8. Display student details along with yearly stipend
Output
Output
10. Display the sum of stipend for students which get B grade
Output
Program-16
Python to SQL database connectivity
import mysql.connector
from mysql.connector import Error
try:
global connection
Connection=\
mysql.connector.connect(host='localhost',database='mydatabase',\
user='root',password='care')
if connection.is_connected():
db_Info = connection.get_server_info()
print("Connected to MySQL Server version ", db_Info)
cursor = connection.cursor()
cursor.execute("select database();")
record = cursor.fetchone()
print("You're connected to database: ", record)
cursor.execute("select * from Student")
data = cursor.fetchall()
for i in data:
for j in i:
print(' \t|',j,end=" | ")
print()
except Error as e:
print("Error while connecting to MySQL", e)
finally:
if connection.is_connected():
cursor.close()
connection.close()
print("MySQL connection is closed")
Output
Connected to MySQL Server version 8.0.31-0ubuntu0.22.04.1
You're connected to database: ('mydatabase',)
| 1 | | Atharv Ahuja | | 2003-05-15 | | 444444444444 |
| 2 | | Daisy Bhutia | | 2002-02-28 | | 111111111111 |
| 3 | | Tahleem Shah | | 2002-02-28 | | 101010101010 |
MySQL connection is closed