[go: up one dir, main page]

0% found this document useful (0 votes)
30 views18 pages

DocScanner 18 May 2023 12-40 PM

Uploaded by

prajwal pawar
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)
30 views18 pages

DocScanner 18 May 2023 12-40 PM

Uploaded by

prajwal pawar
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
You are on page 1/ 18
® fi ne . fy Practical No. 4 st[og 12023 » » ® © ® © © > OD) » ) | Python Insiatovion & configuration ailth usindowss Step1: Download -the Python Tnstallot Go 40 the Python website Chttps: |] www + python ong [download @ download -the [atest version of Python for windows. Step2: Run the Tasialler Once -the installer has finished douinloading, «un the installer by double-clfering on the downloaded File Slep3; Select Installation Options During the installation grocess, youl be paompted 40 select ' which installaufon opHort you want: Make sure fo select radd fython 4o PATH” so that you con ase Python fom the command tine | Step 4: Gompiete the Lasiallaton Click “Enstall Now" te complete the instalatron-This cll? install Pythen & any ae @mponents ante yous machine Step 5! Verify installaton Open the command gompt eg lype ‘python’ FF Python f= installed correctly, you should see the Python yension no displayed ja the owlpah- Congrotulations, you have succesctedly installed Python on your Ultndowe machine! > fograms for understand ing the daja types Data Types — Ye Numemc data types 7 Practfeal Mo. 2 : saledlaaes He Tntegers dala type: X= 10 paint ("Value oF x=", x, "Type oF x=", type (x) O1P=> value oF x =10, “Type oF x =(class ‘int') tt Float data +ype - y= 20-50 print (value oF ye y, "Type oF Y=", typecyy) ojp=> Volue OF Y=30-50, Type of Y= (cless ‘float!) + Complex daia type Comp = sot a0} prine(Value oF compe “snp, “Type of comp =", ayge ceo? . a U o]pey Value of compza0k20j Type oF comp conse eapeieg!) HE Sequence Data Types - aE Sting - str = mielcome 40 Python" pring ("Nalue of sire", str, "Type of sere", tape co) | ojp=> Yalue oF ste = "lerome to python Type oF s#eCclass ‘ stsing'> "=| . 1 contol Flow statements, blocks & (oops C3 —— > Ltet WeGua = L'Python", "Sava" "poe | paint (Nalue of list listvaxType of List =" syge(listuas)) |p => tue iste L"Python”, ¥ op pe! Yalue of VetzL"Pyshon", "Tava", *Pup"] “Type of tisk =Celase'1'si) ae Tuple spuptevar = ("si8", "ghubh2”, "Mahi" ,Aakthu") print (‘Volue of xtupleuare =", 4aplenar “Types oF fupleuar: /xypeCtupleva) |o\p=> Yaiue oF tupleuare =(tsla”"shabha”, “poni®, “apshu") TSPS of tuplevay = (class ‘Juple!) ste Dichronaty gleuar = {Sham + +20, wgait, 5, 1271004 gaint (value oF atetvare" 5 aictuors, Tyee oF dictuas =", tyPe cAictvar) olp=> Nalue of dictuat 2 { "sham: 2, fe ae Type of dictuar =(class rdictonary’) A onlay savi" 3 2, oer, “TEPC oF gor eM ype cee) ele = ea Navi" 3 rare oF cet e(elass sek) rigid” Navi" 3 Tar Nolue oF PPro agua Fi 4p Boolea” 2Fue ' oo print Cuolve oraztartape oF o>? ayrece?) o\p=? + goolean') » or ae (class nade oi arrue 7spe w : LONUeUy Few CLUreMeNnts 1 . else 9 fe*Statement age=20 if age>=18; pint C'You ave an adult") elses pant ("You ave a minor") ©}p=> Nou are an adult- > '® For Joop: | numbews =0412,31415) | sum=zo > | for mum fa numbers * 1 sam t+snum w print ("The sum is 1", sam) \ | Op => The gum is tte \ © while loop : | count 20 : i yahite count <5 | int ("ThE esuae vs i, count) \ count +=! > a ® ® © ' | O|p => we ¢ | IP The count Is. 2 o | The count is sl \ The count 1s >> eo) ste count is +> PE The count \s:4 o oe o Break Statement! u ‘/aumbers = 11,213, 4.57 for num in numbers: if num==3; break y printcnum) elp= . 1 2 ° @ © Cetinue statement : N=Cl,2, 8.415) © for num inn: ' ie ie num 223: continue © peinttnam) » olP » ' a oi 4 s ” 1 OFF statements zs | fer i in rangecn): ie 2 lig ise ) iptoa: Tain ml printciy > | opss 1 2 a \ Pp Practical No. 3 ° “Programs fr understanding Functions, ° ga. Use of built in functions. s @sam - , number = [1.2, 3,4, 9) - +o tal = sam (number) j psint ("The sum of the number 1s." total) Output : © he sum of the numbers t's; 15 e @ count - Ccounting characters) *- > ” sentence -"Hello yorld | 3 2 count = len(sentence) » print ("The sentence has", count, "charvaciers .”) ‘ta 9 Output , 2 The sentence has t2 characters : @ @® absoluze Yolue 2 qum=-> > °. absvalue = abs (num) e paint ("The absolute value oF “youm "iss" abs valued 2 Ourpat = i ° The absolute value of -s 1525 2 © @® sesing conversion — j ° qamber 242 i stingenumbers = sty (numbet) 2 ® print (“The numbers as a Stsing Is." , sting_numbers) 4 output = : ‘ —the numbers as a string |S +42 A @®Meoximam value: 3 1 12, 10,18) values 31% maximurn = paxiwalues) point (The maximum vabue fs", maximum) ‘outpar TRE maximum valve 6.15 User derined functions alcwlale area oF Circle: der civcleareo (radius) area = 3itq keredias #2 , . veturn avea 4 wadius =s é civeleq = civcle_avea (radius) pant ("The area of the cixcte fs. ", cirelearea) ° owpar > ° 4 5 The aveo of the civele {6 + 18-5 ° @ check Er a Number is Even | /° der eventnumber) = r if numberlo® return Tsue | elses | meiurn False ° nam=6 e@ | ir evencnum)! painecnum "is even nd ® ese nrcnum, “Is odd") 5 pant ( > ourput = © @ is even: © Sequence ® cateutale #rronecdl der ‘Fibonacci 6M): sequence =Lo1'J join range (2, 09% 2 sequence Lint Jk sea d cnext_num) Foe next-num ence Li-2T sequence . Fe Fibonacci’ sequence", Hb sequence) Joutpur the Fibonacci sequence -L0,1 1 1213, 5, 8,13, atau @ Convert Celsius to Fahrenheit der fahrenheit Ccelgiug) > Fs celsius k a}5 430 wera £ temp. celsius = 25 -temp_f = fahrenheit Chemp-celsius) Point (remp-celsius, “degrees celsius is equal to”, Xemp_F "degrees Fohvenheit ,") Outpat = 25 degrees celsius is equal +0 770 degvees Fahrenheit © Reverse a string. cler weverseC str); sting 2 sta vreturn sysing text = "Hello, Shubhoz |" reverse text = amyorrse (text) print(’Revesded sting," severse_text) -y Outpar'- Reversed String | zzhbuhS ,olleH yw vdeo e 8 8 288 vvvuy ag eoeeeeswss? Practical Noy ame fo use existing moduler, packages & Ccrecetng modules , packages: apa gram fo we enisting mModwes. mmport math impovt random te Using math module fa calculate the squay Yor OF a number umber = squengatot = math. sqvt Camber) PANEC'The square yoot oF", qumber! 1s1 "| square vot) te Using vanclom module to generate. a vandem no. be? Leo crandom_namber =-vandom.vondiat (1.10) Print ("Random namber:") aandom_namber) Serpe The square spot oF , 25 is. so Random number | Carandomly genenctecl no. bet? 1 eta), y.at Program fo woe existing package . import sequests de sending a GET sequet to URL response = request: get Cohteps: [api example com") print (" Respens © cocle 1" aesponse. statas_code) pint ("Response content", sesponse: tev) Gukpat = Response code :200 Pesponse content : (content csetarned by the APE) oe 8 09 @ G9 e687 FF HF He 8 ‘output > der sy bstract (a) b)- reiuTn a-b der Cmutiply (046): TRIUTN kb deF diuideca,b): ' seturn afb Import math operations wesult = marhopesaions add (513) \ PANE Additon ~esclt : ") sesalt) ! \ eres | = Math_opesaHons. substrack( lo , 3) print C" Sabsteaction +") qesalt) | sesult = math. opemattons. muttply (416) pane Multipifcation . ") result) eeyult = math operat! ons. dtuisoa (4, 3) pant’ Division 2M; wesc t) Addition Resalt 1 & SupstsacHon ; 7 Mestiplication: 24 Division; 3- as 2k ee o r e ss 83 8 809 @ s s p Ger- derine package Packagetry der greet(namey: pant" Hellow,”, name) Packager -py der good bay Cnarne): print (" Goolkye,” Me) from my-packaige import pactugel, portage? packaged «greet ("“Shubhangi") package? good bye("Shuph22") ourpat Hello, Shubhongi Goodbye, Shubh2z Eee ee Practical No. 5 i ig 4 a [et - Programs for implementatt’ ‘ons oF all object- ted / concepts like 7 2 class, method. % class deFination @ ~~ class Rectangle : der ~-init. (sete, length, width): sel f-|ength = length o self-Width = width | der get area(selF): | retutn self-length + self .width {| | der get pesimetem(sele) ; \ serum 2 & (see length 4 self-width) > We Creating objs @ calling Methods > 1 = Rectangle C4 16) 51 areas +1-gekared P = Tl. get persimeterst) ' >| | pant ("Rectangle 4.1) . print ("“Areo?! area) > pont ("Persimetes:", p) > 2 =Rectangle (2, 4) > area = 62-gebkareat) P= Tagek pesimeterc) > >! pant (Rectangle 2") ‘ | int (’Rren:” aren) pant ("Perimetres: ", P) > > > Jurpet - Rectangle 4 Area; oy Perimeter : 2.0 Rectangle 2 Area: 8 Peirmeters + 12 sa: Menu Driven Program to implements [nhesitame type dt Base class | class Animal + der —-init_-CselF, Name) + self name = name 1 der earcselt) + pant (" {sele-nam a is eattng-") der sleepcself): print’ {self-namet rs sleeping") ae Derived class using single inhemtance $ og (Animal) + der _-in't_ (self, Mame) ; -inft--(name) clas syperc:s der horkC self) ae print(” {sere name} Is parking") ese egerT- 0. -e ¥ F@eriued class using multiple inhemtance class. Cat(Animaly der ~-Init_cserr,namey+ SUPErC).__init__¢namey det meow cer): print CZ sername? ig Meowting') ) FDersived class using mattileve inhentance class Lion (car) der __tntt_cserf- name); ) Super init__cname ) » def woay (self): ‘ PINE C$ seip-namez i's seosing "3 ) te Derived class wing hybrid inhesilance D class Tiger (Lion, Deg): : des —-init__¢serr, name): Saperc).__init__tname) > der grow! (self): : paint {" {sername} ts growling") > > te Desived class using theta hiesorchical i nhemtance > | lass elephant (Animal) y der --init. (self, name) - sqpor).—-init__ (name) , Aerumper(seley* . a, der print ("selfname? is tou mpeting e . °° ° @ ® ° e e “we &© & & ‘ SSE jee ~ dniven program def maine: while Tre: PAINE VAX Ye¥ Animal Proguerm AK) puntC's . Dog (single Lohesitance) ") point(s. Cat (Multiple Inheritance") pantc's. Lon ( mustilevel Lnhesitance)”) pant (4. Tiges( Hybstd Inhesitanee)") point ("S. Elephant ( Hiesarchicad Chhestance)") point("s. Exit |") ch cinput ("Enter your chov'ee: ") feces "299 deg-name -inpar ("Enter dog's name") d = Dog Ldog-name) d -ectkc) a. sleept) d batho elip cha = 2") eat_name = input C" Enter cat's name: ") ¢ = Cat (eal_name) ¢ -eate) ¢-sleepes ce MEOW ¢) alip choana"s name = input "Enter Lien's name:") 1 = Lion (Lhame) Leathe) Isle ep ©) {+ meoud<) 1+ Taree) aie ches qe tname = inpw ("Enter Hges's name :) t = Tiger (t_name) break cy tesleepO a bebavke) > tmeowo0 . o +. weary 2 t gnuwl > > elig chess" ¢ : ; > ename - input( "Enter Elephant's ndme: ) j e+ Elephant (e-name) dD erent © d 5 e sleep) 5 e: trumpek o r elip cha "e"s oO point Cexisting the progzam ") break e else? ; io pantt"Fovalld choice, please bry again." drEnter point +0 the progxm © is vante-. 2° __tnaine_" + man 0) D . > ® @ @ 2 > > 2 xe & Ani & Animal Program eK t Deg (single Enhestance) a Cat CMulsiple Sahetance) oy CMalHleve) Snheri tance) Tigks Citybwid cEnhesitance) = Elephant CHtesarschical Inhesi bance) o- exit Enter your chore : 2 Enters cotls name : lado tado is eating lado Ss sleeping rado is maosoind Ente your choice a Enter dog's name TTSmy —tamy is eating —Temy, ts sleeping —Teomy is baring Js Program fox implementation of polyme*phism. class Animal? det sound cseiry « pass class Dog Cnnimal) ; der sound cselF) t paint (" Woor}") class Cat¢ Animal) : e | i clef sound (self): e | paint ("Menw)") @ | class cowCanimnal) : ‘eo! dee sound(selr) : 1 paint C ool") e. i : der makesoundcanimal): oO! 1 animal.sound 0) eo; |e create instance» P| 4g: Pogo WF es > e+ Eat | cos Como 3 Ite Make sounds awning pollenoypintsm 7 gmake sound (4 a | matesound(e) | mate sound Cco) | | at | > Oates loo! > Meoul! Mool eoewewewe

You might also like