0% found this document useful (0 votes)
43 views19 pages

Py QB

Py QB for computer engineering student

Uploaded by

batatapotato590
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)
43 views19 pages

Py QB

Py QB for computer engineering student

Uploaded by

batatapotato590
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/ 19
AGEN VT 2 Question Banke [xe [Ege cpetine : in_pythen ? SE sr a —f-2s _quns when i+ is called 5a) capl od _}-e28 dota, Known a6 pavameters into a unction . A Function can weturn data as os) Write the syntax of Fopern? F open C Filename nnode) | : S| use of ony Pour methods Sn math modu~ Hixesl ec al |) meth. qv ted = Returns the quave yeot ofa I number: x 2] moth. Factorial = Rejurns the fachowial number. 3) math Pro dies Rotinns seine sete WV wnatty « i$ finite: 2 Cheeks whether finite or nok ql Lisk Suit tn class SS aS attri bute cumenration Time a is) MGzeioporan => name of the class. RL. randvle! ef Li. bases cn a] died operate Explain ensures eens ¥ (reeves (ome Thisuiattes wkd | oan co Nene rhe wf airs « sinwea A se Sirs Neu ener load { te Wiiclniemacan Thies ottriibube aansolmeen es of the class. juple of the bose clernen) classe, EP ee Tn python +h |_easily identified. Namespace sparing conflieh iv abe o dyiteshene tensa eal Pee | and matrics- | of high level on thes use of namespace § onary of he class's Namespace. NurPy is python library that provides Support for large multi - dimensional) ana with a large collection mathematical Pumehons 45 _ ewer ay Sine olon . d namespace is names ave Un io _moatntaing the clarity || code. es | i : on ae | TL Desevribe module tn python with- advantages ? 40 Tn python a module te a File ongal | i—python code. typically ~containing d i OF Punstionds alabees € variables. HP) PAGO At ek Used $2 paganize co, Here cseible luni hl 4. ial aah aia 5 2 —Te_aveid Maming conf liek 19 Foch pmedule hag ts own nanaespace which eS Ra TS aed dielPimad W clits in Glee tal dio S WeTsMolaels Wiis, ama ce eee in othey it reodulksi pit eel sige : malin proqvam, Advantages = 2 eee 2] PRiews as ie 3) Incapsulation | 4) standard. library | 3 Third-party Libraries || 8) Namespace Management. 227] PSY ieee eee 8 opening a Ai) >| —__||1] Read mode Cx"! This mode ie the default mode for ed ng: odbilicen tis pens the file fox wea only. ‘Fo the Pile dors not ex'st, a ae Ss awatsed. 2) Write Mode C'w Thies miode wppensminerpaeetper Ovi delle docs Unotexis) aes create [5] Append mode Ca ii aT at This srrede jopen ihe MibeBen Appending . (fp | dye Bile does not ex's}. i+ is cveated Ff the Pile exist. new data ts written Jo the end of the Fre. [4) Read € write mode Cr+) Thig mode opens the Pile for both veadlny . | & writing Ra the aPy len does Wot le2e) Beams Pe illierren ved “NE aie EE Vemmensisth ids contents 4 are oveywriiten J J Binary wnode (bh Thig mode ppens the File dm binary model This 16 necessary Por weading £ wrihn binary Rilice aus as tmages ¢ yidews: | 6) jpese 1 modeCt’ > | Thig mode peng the File tn This 6 the default @nade Fon text Files. 3) Design oa python program whi exception if the Value enher del \ess thon zero- def chects HvalueCvalucd | voll rie eaas _ A alse Voluctnnen(” The valucilnaug: be . —__greatey Than ov equal to pero") | { | j { if ae | : cere int Cinpuke: entem daWaleees 255 a shi 3} aed. Bereinee ev ol diCvalice) | __ excep} Valuebrowr age egos tice) | lsc ® ! print(''! The value te volan) 1c}| write oa Python isreguannehs comeasenele i two strings - Sheil: Oriel ens Sete Oo ee | Str3 = B4r\ + Shoo pxint CS$r3) NV] | State the use of global with simple ee ple: ——>|| Tr eye mtg |g lolea ly SK eyiuens to declare +hoat ao voriable bhould be dreated as a global va rather than a local one, This changes mabe to that vaniab Any = OnE ae se ke iain a) tthe glebe) voriable » volth “he | dome i name | ae z ou 95 esta U 3 a = ae got e a def mai iilewallioe = cae. i"s i _ Bleiseu x a | Az 20 L | erinit” Before Fur call x 5", xd J I modify global dd a | print Co After Function cal), xs‘! *) ied) Me eine pee pene a class g it | object im python? = A class ig a bluepyin} Pow creahin i+ deFine the attributes 4 mether objects of +he class will have. * DCreate a class use the keywor class Myclass } x= SG z) Create object usethe class create objects: fan Myclass on) print (pl. xd pr Persontd Eee; closs Person? Aono e 25 OTe Le Ee Sgyel = Sof ‘pif a ae print icip.nam ed Cen miaCe oe age) Bien John lI 30 13)|| states the use of python class. parameter “selfu to =| 575 elf ts used to wvepresent the cet SoM EPhicw alas with this ingtan— can access the attr keyword, you ibutes the class In python. € methode of Dwithout the gett pama mieiher siyomluee line able +6 accessiithes yan lee eer AM) || AGa) iSite E Sarasa ae mem Ee Liisa ts ytho n ae, i] Read tmodc Cr? 2) Wortthies nadidie lw > 3] Append rrode Cad 4] Binawy ceode Cb) State the ude of mea d/coi gpa ¢ Gir Funétion in python rors Arle handing | mace ha = Lt pee acon Ryeewe | Othe veodt) Gur hs Josed fo Ivead (a Specific, id rerbts of “bates Jc ees iF no ize vs pecihied th veads the endive file JRohken called without an arqurment it veal ere icon cup een 2) _vead\ine 6D |S RBA nie eS Sou hs used to yveada | tach time {i's called 5 Mh reads ihe oext line Prom the Pile- 4 J 4 a oe ic ere es i : a 3B] i} metus a String containing the lin SS eens Bs J Describe veer dAcfined Function jm python DA user—dacFined Fur in python 1s a Function +heat ts created by phe users zy) i+ ¢ block of code that can be sre throughout a program . r 3) user. defined “Run are eveated Um ‘deh’ keyword Followed by the fen & a colons 4A) The body of the Function hs tn the Fur ends with the “veturn! Ae Explain tne Following package example. a => rum Py ; NumPy tsa Python |ibran dacs oa variety ASO Gan = | Twat HO | ont i - : comp) pg Vet pawhiewlarly well ouited Por working with Grrey¢ 4 ake (eey ms toport nurmpy a8 np ix, ig array = Nprovray Ch 219.4, 695 | | ——_anity-= opie print Caray. ¢hape) print Comray. dbyped _normay sre | pea OSS ie Cone pnhe4 pe crise aa [a Sait ate 4 Seavey as louit on bop of NurePy & provide additional Pundhlenaliti! Pom scleral ttelecenam uking iF jretudes modules Por optimizations integration interpolation, \inean algebra datishies d prove, boa ina port numpy OS np Prom Sel py iroport inthe def FCx>> yeturn x** 2 result > integrate print Cresult a | PAGE NO. ATE: bo) Pos 0+ 333533333339 Bead | | 3] Pandas : { = Pandas tS a powerful data poo nipulation 1 be |_& analysts \ibrany Pow pytheo: oy provides a nse Bice tose Uflaipiin sibinls itso mereEnel lay | Week woth wiructuned | dele, such cual ft gabutar data ¢ tinoe evict: Pandas is 1) | widely used Por preprocessing, cleaning ii Ex i caport pendas as pd data ~ “Hare! C'Rar', Bob’, Sham! ‘Pge ) ae 2aS eee) 38]. PE eet 2 LA” ‘ae oss See) print ¢ af) pales rlame Age coy Rains ie ees. Pune du Bob ge as 6 har 3s voK Pay Matp)o tile Matplosi Woe ais ata plotting lib creat ng stahic a eee ie tgualizations (nh Pythome hing ly welly gutted «Por eveatio bar charts 4 isto graros iro port adits (1 oa big “pli piel ¢ 73) os pit. xlabel¢ % +aae\ Sa) lb. ylablel Cynanis™ ) Er laes Jed lei Se tinwis Veta aivem ip Done ipl. show “W]) Greate a clas sDehd dene ae narnc , departvnen bs dilbvell sol AMBRNelaes: ale table wethods For weading é toeiding print ing AOE MAS aticm mene Students > i def Lote. Ceelfi name, department vollns): se\)f. name = hame Self. eee department Sel Ba rel 2 yell ces 4 aecF cread_ info(self)? el\finame = tnputC" Enter Student's Racy | Self depariment: inputt” Enter siidend's Aepavimeny)) &e\h. vo\l_ oz input! Enter students roll no), def mint tpPo C&e1F)* ; By Cas) cde i hakesiabetnne, + Leica laamcinne) PeimdC Department '', gelfs deporment) oi aC RON plumber gelf. voll_ne ) f re RO oe Bisgend| tad An he OD! print GC \n brudent Thformation t Stadent. print _infe > al Btr.= ] Enter | 6tudents tnatne =” John 3 Enter students departenent * €® Enjer student's aires sera) |2) Tnheritance in dSubclas ome ne 1 eee | the Punchionalidy fF she Super | Staden+ Trformatioen | ehudend = amet Joho | art ment? Co Paola gadfaleurtls can see Ea TA raises ese Expl One of the cove conce thon with ex tin CooP) a : - + t languages fs jnheritance. thon evreate iS a mel a thot allows you bo hat are ased on existin e\ a\so abilid @ cx: hoving the chelates ieee yo in class ef tna S e\f. nimal * df, name DAME I> Ma Ee (Bs ee os cre ne 2 pa CS Tine! euihVirn a ley en a class DoglBnimal) : clef speak Cself)* pao C* The doq barks) || elas cat C Animal): | def peak (Self) ' | print The cat meows ‘) wy dog Sap by ce et dione: nn beads Say GN Pe\ ex GD) may. dog - speak) iocsiet See dat, Speak © | 2 Went | The doq barks . aaine cat me Ows- 20) write a python program whieh will throw exceprion tho the value entered b LS evs | till Ve plc in at ra mews DS = Ans 9's 2 Define a Function in python & give example : ed, (See ae a Date ~ Rare) =" “Ex ~ ti SP rt Be ot greet Cnamed ! oe e ape CR Hello | framed apes | © 1P = Hello Roam = 22)| Explain pene? method f waibe gyntan. a => | Tn pytron the Volpent) Runction is used | +o apen o Prle & veturns a File, object | whieh provides methods 2 attributes MMIRoy) Beso launtqumeps Wnty cine) Senmem | | Syntax = open€ File , mode) 24) Explain sthestiMathe Module tn python me ; f four methods: = The python yoath module hs a .buit 7} a module that provides access to A Ao ae provides Af matWemealiaa )) URih A Net ieee 4 trigonometric logay Tthrale ¢ Functions . exp t Pouv methods, ta) 18.40-¥ (>it LTS gli Rimetom nae Square qoot of a This Punction returns thr po- Wer oP fan etme See FSM eeu be es we, Function vetuyns the ee expo nentia) of x. 1S inc Ne nans cum etic raver) vetuns the sing a of a number. | gn} (Ee pion Sweet foetr parameter in puthon Pe necnetaeondelee bt sO she self parameter in pythom ts used to eae oe the current instance ofa elass - A) tt ; used to accesS Wasntables miner A tonite allaisse 5] The self pararctey docen*+ have to be named elf. but Se paeiso bcm aenminaser parameter of any Pur jn the class’ Fal Ex = class Person * d efi tnt Céielifs malenreiimongioman Self. name = name Self. age= age a } lets aeet Cgetf)* a Gh Hie) lon nepey eee mnie 126 es tee pect px 2% years old ". Foymat Cself. name Se\f. aged) p =iperson C' pam\ 28) yo. great ©) e + : name IS Ram 8 om 25 tars old. , oi Ar. hones t Explain method overriding with an a- raphe? ( ad _ Dmethod overriding is « Concept in SSF 2) Method overriding is a feature of python that allows a Subclass to provide its own implemento tion of a method that is alve- ady defined ‘ns its parent class. [ a) Jeis ts ‘useful when you want 46 provide f |. a. move pecialized x customized version 5S. yet (Popa cle etch au) eaemeerelbaes Ex: class Animal? def make Sound Cself)? print Co Anima) ound") class Dog ee 8 def make. sound (self)! printC woof!) class .ca+ CAnimal) | def make. sound Coelf)s print Ci tteowl |!) | dog > Dog) cats Cat) dog - make _ sounde> Ge, Innalkc s sounded ies yo poate ah 3S Meco w |, 1 sched I | 24)| Explain -Yhe namespace & scope of variab! | }o python: __ TL namespa ce ha ganz | DA namespace tg a Systero £ provide a. way to @ccess names Cram Fancthions classes e+e) tn a program: ; 2] Namespace act os 4 boundary +5 en & aveid nam we tha} names ave unigue im conflicts 4 3) Python hes Four arfReren} types of Namespaces: J} Buit tn namespace 3] Global namespace 8] \eca) damespace 4] Enclosing momespace |2] Scope | D gcope refers to the region of a pyre where a parvticuler namespace is dive accessi ble [a] In Python , there ave mainly three Toca) Scope: Variable s defined Num Fur have a local scope. They ave _a only within that function - 2) G\obal Scope= Variable defined at Jevel_of a module ovr explicity dee as global sat PAR en ba ey Senos They ave accessible throug F re rodule. - [3] Buid-in-sgeope: This scope contains naz I mes of built -in- functions exceptions 4 e | 4ypes . fy tg automatically leaded Miner | python Starts. Bell Explain try -except blocks statement in. 1 python eee eee ee =| 9 Th Puthon the * tyy- except’ block s | used for exception handling - | FS atews you te cateh 2 handle excep | Stone way Wiath lp cede lduintmalne—eeeeer Eee es ee eionmennee |g] The excep} block contains the code that | wil) be executed jf on erver occurs 19 = the try block. a) a] Ex = try: i aceult = 1ole printc™ Result” vesult) i enceph Zerp DivisionEyvor * | print C° frre? Division by 2ere" i} eee Error! Division by zero.

You might also like