0% found this document useful (0 votes)
9 views53 pages

Class 12 Cs Practica

Gde
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
9 views53 pages

Class 12 Cs Practica

Gde
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
! © WAP in python +o show the basic fe Funafonality oy calculoter is od Gi def Add (5 ae ae EEE _ Stir =10 =e (OMY 0 while True? os - Sele fotlinput (enter ao) a oa eee es — sort Ce _ans=fnp nuk (add more 00- Sve 0") cpeeeues Me ast 50 4 break paint tsom) def svbt)* a EE Es astoitinpet enter r nol’) Pt OL o __ hie ais __azinttinput Center no) gUbs = Sube-a 0s =Tnputl want +0 Subtract more oe-)"y)n) gastn’? 2 ee break 3 i a: fat subs) pes det mutO. ie __ multe) ts while Tene (LOT nee a a= intl Cinput Center no.) no. mul = mult ta 2 pin k= pub "wont t0 mul mere 0° EB! A oe ee — _ ae Pe ovtput:-O ade/Sve/mul/div add enter no. 3 add moreno-2 Y/n Y enter no. ¢ add more 0-9 Y/n 1 8 1) a break _ priotCrulti) de et ovo Oe 4 ind Unpat enter no.")) divi= a a ae while True 3 Pcs fot Cinput enter no/)) _divisdtviJ/o _ eS Le C want to div more np: Y/n'') Ei in So ‘Teacher’ Signature —_____— TT 2 ©) irite afounction fo python which accepts a no: from ger +0 return true i4 the 09-18 prime No. else return false: Use this funchon +o punt all prime no: from 1 +0100. dot, prime (a); for fin range (2, O//9 +1)* LEOU/ aie tO return False break else return True for 130 range (ML WONA 0 is 2 9 pmme Ct) a= prime ti) T ip oe 3 ) print i) Teacher's Signature mmm Sa Write. pene aire student ana retusns th coark and mmm is oe a Us ef 4 mowks ek @ mininum mark , Maxi room | ___maximyms maxtra) E overage = sum tm) / Len ) ee _retorn minimum, maximum, average m2 lu 040560) 40, 0 107 s Ob, 05 -anolusieém) {pa Carb, ¢ Teacher's Signature r— S { Text File i SHRI KEN DRIMA | VIDYALAYA pu L 2 i ee ee ee a eee j—}—- , Hello | I Love India | PM SHRI Kendriya. Vidyotayo ) Port ' =— = = Output? - Total yvowelg= 13 Totel Lowercase =2Q Z uppercase = 13 Consonants = a4 P Oo WAP to read a textile “muff il e-txt” ond dpi +he no vowels z fovee ae. ae - a eee nner eee ih open.t'my Fite mE Zasrde) ae : dott = Elk cceadt DB} ‘ re vowel =a fouA£TOU ” famed’ = CLE Ce = 6) = —eoneinue ies alfa i t-te lower C) * _ ia oe eis c = clatours pU tC) pant (“total | yowels=',cv_,‘\torbal Lowerece =") CL, “uppercase =", CL,“ consonants =”, Cc) fr: clase) a ‘Teachers Signa i ET | How are You LI am good | B | abe | [“Hetlo\n”, “How are you\n" 5 ak oun good "Bye\n'' (“How are youn”, “Tam geoa\n" J C“Helloln", “Bye\n "J (13) 6 ae WAP +0 remove all the lines that contedn tne fe character 'a! fn a File and waite ft anothe file fiz0 en Cmytet tts oe) a a= fi-readliner() _ a retort) “d ss Vie | a [Link]) hei i Bs Uy Sal afl ee, Stk ae z Laas Lea 4. as i aeeabiat for Sind? Lenten ie Oana z ___ly-append a) iz 7 dt) ep erd ne ep f= open Ceopytxt--xt” "eof f= open O mytat txt, S47) fy writeliner (0) £3 + wartelines (1a) Fy: close. C) f3- close) peiniticae Txt File aa writelines) © Hello Potato f¢ a yegerable Table ( ( ( piel Output— Potato iS a vegetable Table WAP to cweate a textFile and paint the lines starting with ‘T? ow 'P' (goth uppercase and lowercase) be z ae £12 operall NaN Sc setoketa 9st) Se LC" Hello/A", ‘Potato ico vegerable/y “Table/n” “bye priya/n”, “oeege i/o a ae aed Sofi write Unda ty) santa os fi -seeklo) a reader= £) - seadling: 0) ae fy closet) for 7 In weader: - i fi {& Tod 2 in“ Tete”: pot) Teacher's Signature me He fs a good boy She fsa gist He fs ram She te e?ta He She He She He | Bye prequenty of He= treqvency of She= 4 oe : meg Oe Read atext-file to prfpiithe frequent % she. ood tHe’ ond 'She’ found in the File« Fie open (Smuytxtetxt he) ee d= fi -weadtoec) jib. 2) ot eats oes 4): closet} (7 tee) | pass 0 oe eae counthe = Countshe =o att ct for 7 iod: ET eounthe t= } -count tHe") ot a countshe +=}. count ("the ) pa yrequency © Eau oeae ; ceunehe J point C Se she = + eon he Teacher's Signature Output <@ enter poll 4 ede enter name khushi add more? You enter roll 2 enter Name hrutike add more) Yes enter rolls enter name dhani add more N enter required roll © not found 1 aOR! ee 5 na re 2 emer = sail Create a binary ffle with name and collnumber- Search fora given roll oo: and display the name, iP oot found pana ot ee 13 Lae) —— looport pick Le_ eee fl = open Cbinary. aot, ont) 4 | eh). while True, coll<= int Cipput Center oi Nome =input Menter name”) _ 1tTnamej= roll_ ans= input C'add more 9) Lyons? fn to's = break pickle. clump (t,#4)_ {i = in on er re 4, ived role) C=O i “_f1 2 open C"binosy- 1A) 2 Tao IEE load CF) _for_k,v in data. itemet)? a ——_ i yer? ss eee =4 | aa Tal essoy 4 paint (‘not found 377 boeak except FOFEN Or: #)-cl0S oe Teacher's Signature Output : — © enter rolino 41 ~ enter name a enter mark: 90 add more? Y enter rollno 2 enter name b enter mazks TS add more? ¥ enter rollno 3 enter name C enter marks 100 add more? h required roll no to be updated C Updected moaxrks 50 rhs teat 1 ae) Create a binary File with roll no-,name and marke - loputk a [Link]- and updote the marks — impoat pickle Ma St sii Fee ee | fy = open (binary. dat", Sab) k B i= aa Ss white True: ne meee at _ rt sint Cinput (enter rollno!)) N= Ippuk pt enter name’) nee | Mae ig otc (CRE ne Trig eres ee A+append (Ero, mp Br tas iayaea(Covelel myc de) __54 Rip isn _ eae _pieklesdomp (1 £1) fi: closec) col. = Int Cinput required roll 40 be updated’) ) opdatemarks is int (input C updated marks’) trys oF = open Cbinary-dat'",Urbi" ) Beep ia imu” data =pickle- load (FD _ Se povanianineciaeaes i+ ilo == rol): rib) ec ateln as er sont totoctoe as c ‘break eX Cépt iO) Ait ora €, > close) zi Teacher's Signature i Ananya =o Aruntyott Debanshi Output :- CV, tAbanti ka’ ley ‘Ananya’ J SS “Arunsyott”] CY’, ‘Bebansh??] Output : - userid o pascword 4 wanna add mowe rows? y/n y usertd b password Q wanna add more rows? y/n Y userid C Passwowd 3 wanna. add move rows? y/n y usertd q password a wanna add more rows) y/n n enter userid whose password you need C 3 ——— ee = \e Pt €a random no. generator that gene roves rand om nos: bekween 1 and b Coimulaser o dite) Thretnthel dice for lo times and patot théte total _ jmpowt random ae |foritn range (1,193 as random . randint ( 1 a 9 OO) ai ais Oa Somt= O& j print Caum) oat aaa Teacher’ Signature WAP to python +o demonstrate neat gearch A= 11 Ree Sa one S a0) eean print (Ust fg", 95 Cease st 1 ssa a= int input ("no-to he qoarched 2")) ‘for? Pn t 3 Ga é ease i ee | ey Soe | Pesan no eee _bereak Teacher's Signature je aa Xan < ystog data. st rineieeteanll wae to fen plement o ote stack = Le Dees, ma é def pus): by=01 9585 @ Tee _ Rigor es m 2 Stack-append tid b arnt tstack ae d nia ~ cle _Spopl ~ for 1 nlata i a as ctack-popl) ; pe pol UNE Gek semis) Mae SpopJ > Lenoth 0)? b= Len (stack) __pafat Ulength oh stack te", b) jtengunt i — Teacher's Signature eT lwae +0 pase an Piedad Ustag ‘augae Us a fonetf and push ee those elements fn the otack whith ard dfvisible oe H stack = J_ det Aiv(p)? for f fot: 6 fh ty t= = 03 —___ Stock iappendt) sa! fi paint (stack) 2 DGS eee 2° Saal) laiv( 2d Teacher's Signature " eT Querfes _vsing iGO Net ae C fen Wem w In CA) LIE A Ce) (SDL » te) enden ae ge ee “Sele | ca) Select dictinct (pEeT) _ i rom EMPLOYEE $ (bh) Select NANO: trom EN ployee | Where EXP between © ana 45 tc) Select ROLLNO: __hrom CLASS lephere NAME In Ca’, tg?) 5 wl Select MARK — $rom, CLASS where _ a = & | 4ycom clase __liphere NANE (8 Noll 5 (f) Select ) com clase __gorder by MARK __boving ROLL between 41 and S 3 @) select count Ch) > CITY ___ trom EMPLOYEE Group by CITY 5 Teacher's Signature Output — © Ge arene) a wy) 2d tb) [Bvg (maak) J a pov iminitmot) | i a ce) Seem eas aS Fee Queries for Agyrceagate foncHons 1— cad enmed, (b) Avg) » Coymin €), Cd) ma. xin) 5 166) ain} € i ta) Select gum (EXP) cae yom _€ MPLOYEE } Cb) select avg (Mark) From) CLASS col geloce mintmasck) __ ftom class), td) Selec max (sald | Aron EMPLOYEE § “te cetect count) _| +-rom_C1SS Teacher's Signature __ | Output: — @ | Query OK, © rows Gi ee) ha? ta cannes? pythanainidn seg ala a connecty| Ay ond | er foun the to owing Loe on dat in data. bale? Cneckale erate a Import mYsal: connecter mydb = meat con: echor- connect (hosts ‘locadhost)) 4 bi passwd = 123, | aes bsername Scans Aakal bases hoot’) my Clr muydb:crpsor mycurs execute L (“ Create table clace a CROLLNO, int, primasy key ae Alame _varchar(3o) Z mack int)" ) muydb-cloce L) Teacher's Signature | Output: — © Query OK tL row affected (o-U# sec) Si oe P WAP to _coinneier Python with MyS@L using dostaboue conne CHvity and “per{oam ihe following operation on cata _in database! Ingert record in the table Mmport mysql*connector i i Ee mydb = my sq Ls connettor connect (*h oct = locathost! a username = ‘root’, _ ee Ela ener myurr = mydb-cureord) a myourr + execute ‘ Cinsert into clase Res) ale, ith e228) a mud be commit () m 4dr ¢ tose U Teacher's Signature outpud?- Query OK, 1 row affected (O-dbsec) rows matched 4 changed! 1. Wasninas Genny. python wi aloe connate cee the {ollowing. Operation | on dot in database } mee the tav\e _ Import rngyeop.~ tconnettpy — “eannector connect Lnost = localnost), bi ____ysernome= rect! __ ae posswd s Wek ae a ear Vochoou ) _my@tours mydb: cursor O) My Cu = Ce Ces _(“Svpdake clas ¢ ae mosxk = 100 where RolLnd = 1”) reydis: commen £0 — close) Teacher's Signature g Pa eee i _J WAP S So. a aan connect Python with mys@L ucing database of ae f Fosiro_eppmecivity. the i \ to a! dato in clakdbare! belete cocprd from) | impowh mysql sconnector mydb = mgeglscommector tonne ct (host= ‘localhost’, i SE i peername s ‘ypot! poserwds 123 = School” my aur = mydl=curcor My Cues 2xeCUre = Upebete a Dorawatu ee Wee Seooens ioe) a mudb-commtU niyo closet? Teaeherecipeature

You might also like