Practical
Practical
1f 1
count=count+l
print ( "frequenc y of he and she in file " , count )
OUTPUT:
- - - - - --- .J.
PRACTICAL-9
22 of 57
22 I Page
23
AIM : Create a binary file with name and roll number. Search
for a given roll number and display the name, if not found
display appropriate message
CODE:
'""' ,H pickle
def write ():
D-11
f - o~n ( .. Studtntdeta1 l . dat · , ·w · J
Wh1l• 'Ttu• :
r • lnt (Input ( " En tor Ro ll no : • I l
n• input 1"'£nter ?la~ : • >
DI ' "" 11 "°'
DI ' N•:ne · J• n
l•r
plekle.duap(D, fl
eh• lnput l" l'.ore7 (y/nl " )
lf ch 1n · un · :
b.tfoa~
! . cloae(I
del Search ():
!ound• O
rollno• lnt (input ( '" Enter Ro ll no v hose naoe you want t o display: "' ))
f • opt!n (*3tud• ntdeta1 ll,dat .. , '" rb• )
uy :
vtul• ':'r~ :
rec•pickle. load (fl
1( rec( Roll uo· 1- rollno:
0
OUTPUT:
24of 57
24 I Page
25
AIM : Create a binary file with roll number, name and marks.
Input a roll number and update the marks.
SOFTWARE USED : Python 3.12.0 64-bit
HARDWARE USED : Keyboard, Monitor, Mouse, Hard disc,
Ram
CODE:
urt rt pickle
J'"r v rito ():
t•open c• ~tudentdctall . d•t • , • wb ' J
vhtl• Tru :
r-int Unput ( * Enter Ro l l no: • ,>
n.• input ( '"Ent~r :lam.: '" )
. .1n.tUnput. ( "' £nter M.ai rk>: • ))
record• ( r, n , a)
pick,le.duap(record, t>
ch• input ( '"Do you v •nt t o enter aor•7 (y/ nJ · J
1t ch Ul 'Un ' :
br•• k
!.close()
dt-f re• d ():
t • o~n C- at.udentdet• il . d.tt • , • rb ' )
uy :
v tnl• ':'rUill' :
rte-pick.le. load ct J
print (rec)
ucntJ t E.Ortrror :
t,close()
1.U/'f upda te ():
f•os,.n ( '"atuden tdetc111 l . d•t • , • rb• • )
roll no-int (input C- &nt er R.oll n o vho :e nuie yo u v a nt t o dhpl &y : "'))
u ·y :
.. h~ le ':'tV'P :
poa•f.t•ll()
rec-pick le. lo.d (f)
1t rec(OJ - rollno:
ia- int ( input C-tnter U'pdllt• M.a t k a: '" ) )
rec(2) • i.a
t. seek (pos)
pickle.dwlp(l'ec.. 0
f p .d nt.(rec)
exc•"t ~0FError :
t .close O
write()
readO
Up(lat.-0 (J
read()
OUTPUT:
25 of 57
25 I Page
26
Enter Roll no :1
Enter Name:hitesh
Enter Marks:44
Do you want to enter more?(y/n) n
r1 . 'hitP.:;h' . 441
QUERY7:RENAME
400157
40 I Page
41
QUERY7:ALTER
mysql> alter table studentinfo add phone_no int;
Query OW, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0
QUERYS:SELECT
mysql> select•from studentinfo;
+----------+----------- ♦ ---------+-------+----------- ♦
QUERY9:FROM
mysq > se ect name rom stu en in o;
+-----------+
I name
+-----------+
Hitesh
Tushar
Ritik
Srijan
Vaibhav
Manish
Deepanshu
+ --- ---- - - - - +
7 rows in set (0.00 sec)
410157
4 1 I Page
42
I name
+-----------+
Hit:esh
Tus har
Rit: ik
Sr ijan
Vaibhav
Man ish
Deepanshu
+-----------+
7 rows i n s e t: (0 . 00 s ec )
4lof 57
41 I Page
42
QUERYl0:WHERE
111y s t1 > se ect nan1e ro m stu en tin o;
+ ------- ----+
I n ame
+----------- +
Hitesh
Tushar
Ri t ik
Sri j an
Vaibhav
Manish
Deepanshu
+ ---------- -+
7 rows i n se t (0.00 sec)
QUERYll:INSERT
y r.ql:• 1 w , 1..• 1·t 1nto '.'.tudt..'nt i n ♦ o ,...-,·.l,1~--..(0056, ' lw.h ,u ' , ' ScH·nce ' , 36, &~8!.i65~35) ;
lli' l"Yo~ . 1 1·0.-, ,l ffl:.'cb..•;:l (0 D) ' , ('C)
y --. q l> in s<' 1· t i n t o s t ud<'nt1n f o v~, i.uc--..(0059, 'Rit1J.c'. ' Sc 1c-nc t• ' , 5 1, 956565535 ),
LIC' l'Y OW , l r o1, ,1 f f('C t C'CI (0 02 S('C)
y •,ql > tn•.t• i-l in t o •,tudf'n t1 nfo v,, :u('•,(0559, ' S r 1JcH1 ', 'Sc 1 r n c c- ' , 30 ,9 8 11 565835) ,
m •1· y OW, 1 1·0:1 .1fh•ch•cl (0 OJ •_. l•C)
QUERY12:UPDATE COMMAND
mysq l> update stude nt i nfo
- > set mark s =33
- > where a dmin _ no =~56;
Query O~ , 1 row a f fecte d (0 . 02 sec)
Rows matched: 1 Change d : 1 Warnings: 0
42of 57
42 I Page
43
HARDWARE USED · Keyboard, Monitor, Mouse, Hard disc,
RAM
QUERYl:DISTINCT
mysql> select distinct stream fro m studentinfo;
+--- --------+
I stream
+-----------+
Sc i ence
Commerce
Arts
Commercee
+-----------+
4 rows in set (0.01 sec)
QUERY2:BETWEEN
43 of 57
43 I Page
44
QUERY3:IN
mysql> select • fron studentinfo where stream in('Science');
+---------- ♦ -----------+---------+-------+-----------+
QUERY4:LIKE
mysql> sel ect • from studentinfo nhere name like 'H%';
+----------+--------+---------+-------+-----------+
I ad min_ no I name I stream I marks I phone _no
+----------+--------+---------+-------+-----------+
54 I Hitesh I Science I 44 I 655555555 I
+----------+--------+---------+-------+-----------+
1 row i n set (0.01 sec)
QUERYS:IS NULL
♦- - - -- - - - - - t - - - - - - - - - - - ♦-- - - - - - - - - -♦-- - - - - - ♦- - - -- - - - -- - ♦
S ro,.1s in sH (0 01 sc,,c)
43of 57
43 I Page
44
QUERY3:IN
mysql> select • from studentinfo where stream in('Science');
♦ ----------+-----------+---------+-------+-----------+
I admin_no I name I stream I narks I phone_no
♦----------♦ -----------+---------+------- ♦ -----------+
QUERY4:LIKE
mysql> select • from studentinfo where name like 'H\';
+----------+--------+---------+-------+-----------+
I ad min_no I name I stream I marks I phone_no
+----------+--------+---------+-------+-----------+
54 I Hitesh I Science I 44 I 655555555 I
+----------+--------+---------+-------+-----------+
1 row in set (0.0 1 sec)
QUERYS:IS NULL
44of 57
44 I Page
45
45
QUERY6:0RDER BY
ny•,c1l> •,rlrct • fro n ~tLJ(t~n t1 r f o or,l<•r t,y n ,,t·k~ <l<••,c,
t ---------- + ----------- ♦ ----------- + ------- ♦ ----------- ♦
QUERY7:GROUP BY
4Sof 57
4S I Page
46
OUTPUTS:
1 record(s) affected
-· \----- ,··---
53 ol 57
53 I Page
S4
55 of 57
55 I Page
56
OUTPUT:
56 of57
56 I Page