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

Python CRT

The document discusses various programming concepts in Python, including data types, functions, and object-oriented programming. It emphasizes Python's high performance and security features, as well as its flexibility in handling different data types and syntax for printing outputs. Additionally, it covers initialization of variables and the use of multiple print statements to display values in various formats.
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)
2 views53 pages

Python CRT

The document discusses various programming concepts in Python, including data types, functions, and object-oriented programming. It emphasizes Python's high performance and security features, as well as its flexibility in handling different data types and syntax for printing outputs. Additionally, it covers initialization of variables and the use of multiple print statements to display values in various formats.
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
6lHaoag ‘A What %s the difference between ,{arca; py tion 7 C5-Cis Oe programunfing langue | FO- Bo:1- of hard Aave. componeng stn’ cepend a on ¢ coding, Cc prouides high perfosmance, So ¢ is Known og most ‘important programming languag e Ex. laptop. Amplifier, Ac, TH. ete Topics ute should Know etn © progromeriing x Functions Cpesfoimance) x Aways CSecurilg + Performance) x Pointers CAecurilg) % Structures & uriiongC Performance) ¥ File(Stovoge X Sti J > Jauaz Joua is the - best progromniin pecauge jouto prouices hi h Security & High per forma ne, by “sing t Citented progeny | concept we increase security & Perfomance exs Banting Applications ? 4 olusaalla’ language Pittons Python +s wey cosy prog 9 te deuelop Moy applications Cmodnly wteb applica Hone) ex: FaceBook, Tinstagram Age Traportanc & of ct+ts ye While tansPevine cthe. Pace we need .some “Pro * Foy developing ctrese protocle ctt highly Kecommendect b> -transfer the data fast — Eithion Progamming s + def; Python ts hi hlewet, aduonced. genera Fuspose and Object oyiented programming languoge is il dala. one place tocole GRE HTTP TEP x Python Suppor & s ~v > Scripting Concepls(uiithout Functions, Syntax) Function Concept ~> Object oviented Progamming Concept Scripting Concspl} Cistthout functions, syntax), x Python jis the onl Programming language chig Suppor § Scvipti ng language concept x The meaning -for scripting language is no need follod an syntactical “ywle,” Gke end with ; * declayation of dalatype Gke int, Float, 7 choy ete Output Function in python: ; 7 TO paint any text of any Ualue onthe output Screen You need te uge a prectefinel method. Cfunctton) | prin! ~yTo. print an ‘text string ay output “in Python we need to uge “the, follouing Syntar paint (* \, “". “zpvompt>) output $ My rame is kacitha the output depends on the noo t prompl, we use with a space tn ‘blu each prompt % Inle can change “the output baged on the yequirvement editing the predefined Variables tralues GRE “Sep fend x the default ualue of Khe default value of end ts backs! sep is empty sep lagnn end" exas print Cone’, 'twol 'tree') Output? one two “three He The abore code 1B printCtone’ ‘two', ‘three! sep=" » atte can change the ualue oF Sep exs paint Cone’, ‘two, sep=' +) eulpul: one $ (Wo tthe default value of enc is ak ule con chang Ake alee | ‘internal peintc' ones) oe end’ Print(’ two!) print Clone! end aii Outputs one paint Cttwolenrd='s') two OPS one, two °F on) EG A na tiv(] the above cide ig, intermally print Cone, end=‘\n') Print (dao “| end ="\n") a Le a python code I pA’ ols Gne by line using sing & you Forni Wy membey le print Function. Ee Lakshmi Redey «MOY ‘i ‘rather name 7S j. Paint’ nawe is tlenkala ravoyarornnad. + koi, outpuls Father name +S fakshri Reddy Mother name is len kata narayararnd karti . : O22 Wile O python program to print branch Pare: your college Gne ne eae pring: Ci ese! salrtc!s' ECE SRE Wn) apie nie 1 by ube CSE _ priv : AINL d ec€é each characte, ytkon code to display Gne usi ng o Single Pring O33 Wyle a P of your name Gne Py function) paincc('k) Woe sep='\n') outputs K a y aH Haoas oy) blvile 2 python prgrom te print § best Fay names using side by side using mulkiple. pririttus prink CAs’, end =") outputs print C'vams', end=' ASA Yoms Tyo preeth Tsu print C'Jyo! end=' D) j : print! preethi | end=* print( thu! end=* ! e by using & pri E functioY Print Ctorang e “Red, 'Yetlow, encl=* PYINEC' pink | 'Green', 'Maron!, sep =" ‘ 4 output $ Ls tre are not oat’ ; Z “nn pep defer! Orange. Red Yellow Pink Green Mayo 1 gos! cn using” sepend at The Same time Pint Clorange', IRed!, * 2 t ; ed 4 a } = : mca ad eee Pe Lend='') Serer stiri amet ter Oe Write a puthoncode t printany & comes named Ne by line using 3 print function print (' Jova ‘python’, Sep=!\n!) Outputs Joueg pantctct, ‘ett. sep='\n) pithon prin tC‘osa!) set Printing value ‘yo. python gztle can also print % type of ualues in pron} Basic common typer of Ualue, in prthon|dalatyres: int; 10,20, S000 eC floats s,aes et complex: lots, US ta) el& a swe can US uppercase $s lower Coxe J Ske ualue of § 1s Ft sty ‘ABc!, ‘Inia! boo U: True, Falee xthe game wle(sep tend) ts applicable for ualuer algo : Wile a python code to print Output oo Follows 10 tre given wale .uging single pinta bake asingle sty calee pYint Clo, isin the fier uolue', sep='\n) -y Write a python code to péint & complex ualue Lneby Gne using Single print Function st peck pantCiotal stat Ge SPAIN!) ota} stai > Wiwile a puthon code to print 3 Fd valu y complex ualuart- S boolean value, Gne by Gne Print C10,20,20 Sep="\n0 ~ Printlats}, SHEL HR, WHOL sep ="\n') Print CTrue, Tae, False, sep ='\n') . ~Pulile a pytion code all common type of uolusy ‘side by cbte. _ PrindC 10, 20.0,10485 , 'ABe!, TA) ‘ ele can print the real part & Imaginary part fon, O& compler Ualue ex. print Clotay) te lotaj a= lor : print (ao +b 1+) print(aveal) tH 10-0 print (atnag) Ft 4°° Pint Ca-real +O-imag) + 14 priint( tts) sxeal) tF LO print(ats)-t wag) + 8.0 CARS a=t-a3 . paint ad) +e F-8) printCa-real) FEO Pane Cabo) 4b -2.0 Print Ca- rea +Q4 mag) + 5:0 THhitiaWsation oF Ualues: When we neecl Inittalfsation * TF our yeqwirenent is to we ang type of udlue multiple time, with tn the Some print) progion hen ‘it is highly recommended te stoye the ualue tn a mMemor * For “trol We need’ a space * : Pace tn memory a ualid vame for thot memoxy whichis kr NAY, uaviable name ov name of Ahe merry location Cope ss AMG. int a=lo: Print? C/A ads Ar ro Where int — primi tive datatype I predicted dale type ae name of the memory location|vaviable nane =- assignment operator b assign, tthe value 10 %6Q | I9- const Ualye print the text or Ualue’ sfod- Format spect fiey ¢ Conteysion o age8% Ponte! one a=l0 ILiniGiaGsationh of tnt talue int b ao; Il initiabaation of int value -d “ arb) Mpyinting a% b ualuey print € ( output 3 1028 IL envoy 2 tS alread: defined d 6= 20). print# Cd hd aes ualid ~ '020 JAuas ~ sane Yule ay © ete allowed ~ multiple declarations ave no! an pythons _frore is rot declaration So we can wibalise WY yl — 50 concept an prthon pe of colue Fang no-of times - — Because python “ts dynamically typed progamniing Conguo: 2 — plhich *S TOE Supported by any other progia rant "9 tarquoge. Ae injaua inpython a EG a=i0 & plimite OT porobyect Object point (a) +10 fined sine | fixelsiee not Fart Alae ai ¥ gbyle by le O~10 abyl wey bo =20.5~ x declayetke declare the santas paint Ca, by i lO 80.5 oT nT ink OF 105 afi | wh alos a a O -every We on tne, Different Hays Initialise valuy f& a 7 uavlable in pythons 4. Single uaviable: tnitialigation a. Multiple “cariable initialisation | 3- Multiple tariable’ "with Same ualues | 4 Sequence. onpacking by using Gstor tupte | j STnitialisation of multiple uaviable tn Oy | 4. Single layiable iWitiabsation : Single uaviable esingle calue a=lo a. Multiple Variable initialsations —More than One variable & More thant one oly ~ Rule is noof Uaviabler should be egual & root Utaluey 1 Cage 4s ' a=10 ' \ b= kau! | C2 a5 | cajeas . . Abie E= 19,20, 30's; +E Python specific code yb Suppoy olke.. Canguoyt 3. 3. Mutt ple Uariables eatth Sane Lathe, . cosen3 Q=10 bat =10 C8EQ3 ga b= CH 2d 1, Sequence wapacking by Using Gst 0 tuple! Uist=C 1 duple =a) “d — Cage As = (10, 10.5, Tee) Ft Packing ~ Ust element Paysa “HF Onpockt ng P=10,9=10-5 , y= Tue Cage Qe a= CO, ec!, 9.5) +f packing - tuple element | Puy =a at one 09 aaa 5. aritialisation ef multiple canon Hiple Saviables io single Gnes case 43 A=10 b=a0 c=4d as azlo,b=ao, ¢=40 pile a pytron, code & initiaGse stunome age and cl name by using typer az [‘kaut', 20, ‘oceT'] Outputs paint Ca) Ltkani! ao ‘ocer'y Pan=Q Koti print C PDX, sep=\\n'!)_ UceT Livite a python code t “initials & employee name, need Cat Pala ie Experaince & depay Ement- nam by Ng typed & types Type 23 rome, Salary ape, Dept = 'ABC!, 80000 @uyst,{IT! pork Cname, salary, E4P&- Oept, sep =‘\n') Type 4% employee = C'TK', 30009, tgyrs', {ITO BajTs= employee Print C Pav 52 eep='n) Als) (A. program ts pant © best fidg namey Mine by using Si le print ©) a 4 ty initiause & different walues using ty pe2s- prink alt [Link] tw witiase yeal aro nd part of each value late he initiate = diferent typa of Halt pine initialise s ditfer with some ualue and print meee Gne 3 complex cealues & print 26 Sunpack onk Wariables of ealues 6. Rig & wnifialize YW FAUOURNE Tn Oe and print line by Gne using single priintQ +. Program le “nitiatise + course Nomey%-Cos ,, each courg e using ‘type a and piint the COurge name onl 8. Pig & pint the Sum of 4 compler Lalue, 9 Ag lb print the Sum of & boolean ualue, to Ag ls initialise s ditferent values &S ditferey Uaviables and print thes types O13 ni tialise 4 Complex Ualues and print the tmaginary ancl yeal pork of each complex value, Gne by Gne using a Single print Cusing types) complex = ClO+S] , BHF » LER) +ItS) WY r3,V =compler PrintC-aA-veal, [Link], y veal, Y-IMag, §xeal, 9 mag, Vtealy t-Linag » Seps"s ') ' Output $ ; 10-0, $0 3.0, 10, LO, 2.0, 9 5-0 D print We output a9 follow “TN OIA" i t 1 is Gxeat print’ “TNOIA" Wn ‘is'\n Great ‘ ') 3) print the output a3 follows WI PHNEC AWWA!) 4)initialse s boolean ualues and prink using type \ pea a> Tue | b= talee | c=Twe d= tive & =Falbe ay epee output * 5 Tues False: rue, Rue, Fala e ae 8 arb Cid & = False, Tue sue, Falee, hue & * print bc, Le, sep='- ) True ~True~ Falge -Tvue qa -[Tue Falges Tue yTawe True) py eY as pring my WA) SP 2) e, Falge, THe True, Wud output $ Te az=Twue ; b= ralges C= WUC 5 deTrue, C= He print (a,b, cde) Olp3 Tue Fal6e jue TF , 94.2026 & initighse a sting walt Angler ay initiatise any sty ng bageclor) -s We can also the Foulowing syria uaviable, * Vara = 'sty! end ' i \ a,b = ‘America Piotr tre above Syria the first chovacter is opigned tthe fast tuaviable and alk the venaani Caviable cng chovacters will be aypigned w Becon Ook b ='Araetico! Qyb = india!) Prine) ata print Carb) pe Eon print (kb) FHrmetien Xo, ¥b= ‘India! ¥A,b~ “india! prt a, ¥b) HEI Print (ka) + indi if We Wank b& prink “in Gist Format Okb = inde’ pinkie) # Cina GLa €a,¥b= ‘india | printCKa) printc%b) 7 5 } > rle cen also print addven of averiatle/ug, “Fotis we need fo use OW predefined 4.) id 4 exe Ax=1g PaintCid CoQ) SE LUO FAR URISOSAUY |; b=10 pa ntCid ced) sy LUOFR BY BYSOS79Q Reading input calues Prom the “ee an.c: —hle hawe a predefined function scant Cj & Yeacd int, float, choy etc- ~ getscy ~to sty value i ~getc) - & yan mulfiple Gne tex Indaua: ~ Scanner (Some methods’) ~ Cala Thpulstream Cont one mertisct) ~Butfey Readey Conly one methog) In th 3 N\ The Same Woy in python: ; ~be howe a predefined method inputcr t veod Y type of tale . ‘ ~The default type of “inputoo functions stripe Syntons Uovioble. name =% npukea eK “OMe =input (> PT Bewed on Yequitemenk we. |Caating Foneong can ue type —the most commonly used type casting functiong OXe* To conwert sty &-int neo | cate tact Floater = T° conuert Sty te, Floo s complex = To conueyt stv & complex 3 poo LC fevale> + T° conuext stv te bool > exs & conwert St? te integer az int Cinput) stecoge 45 a) print Center pen cos pen-cost =int Cinput©) +F 10 print typecpencost) ielon: "tt! > Hage 2s pen—cose = “nt CinputCenles per cost: ')) #20 print ClypeCpen-!) Wile a python code Currenk plac e & print teat ee TONE Da native - place =‘mput Center your native place cunvent_ place =inpud (tele your Ceyvent place:!y print Cnative - place ,curvent- plac 2) while a python code ts yead today dale & & and print dale only 3 time ‘d dale =‘int Cinput Cenler the toda: doy = input(tenl& the days’) print( Tate /Tdole , rdate » Sep al ) hile a python code to yead one bool ttalueang pink Ba time, bUalue = eualCinputC'el& , boot ualue')) print C b_ualue , b-Ualue; b-Ualue) ntoteg TL we Uge a prectefined method bold phile reading any poolean lalues fom WS, mk 1s Tue only sire clefautt Means 1£O¢ five on text @ ‘input Gke andia, hella he vesult is Tae” only : To yeod “tre boolean ualue Uke True ov False pe Should Use One more predefined eualc) a unc) a specially ene — cual input Ctenla& one boolean value) print Cb) : pavile o& puthon ¢ 2 flock Ualues anc pi a aiink Cinput Cele one inleg : peint Cinpet Cenle gecond lege’ cole’) c= float Cinpal C'erlee fivst floot ualues')) y Plt Cinperc tele gecond f : 4 date : I dexigned foy boolean (ous ocle b yead a integer value; re all and e- float Cinpet Clenley thire Plocd Ualwe : )) int C'TWO Integer Ualues are : *.a,b) é pint Ct three float caluey are x ed °) Gd, o python code ty vead 3 boolean values 7 hlyile x Walues anck print the Piyst booltialue & ample tayt comple cealue a ectal Cinput Center fivst boolean “calue + ')) becual Cinput Center second boolean calue : ')) e ewalCinput (tenlee +thivd boolean value : )) eva = complex CinpukC tenley “Lays comple value s')) eva =complex Cinput Crenler gecond complex ualue =) cva= complenc input Clenlac third complex \alues')) print(the first boolean calue is: 0) pint C' The last complex ualue ts 2 Cv3) ulvile a python code & read 3 stving Calues t print all stvings St 4 =‘inpus Clenl& one string iy Sta = input Clenley gecond str p) bs = Input ('enléy third sting’) pa ntCst4, sta, Sta, Sep ='\n') Reading multiple alues In a Sin >To vead multiple value, of a same time ing Single Une we neecl bo use a predefined functor le nes Spat sAnd the moat. important vule ts pohile giving the Vnput unin spat whe need & Use an empty Space blu tv pus calue. « €x+ one too three tH space most important the pexk tule, the noof WMput Calues Should be eqwol ts nook cariabley . The reagon for space mM blw % The defautt axvguement walue mput alue t& 3 splitE 1s empty spac EX, Opyurtvyy) haere | OPT 2) y —wle can change “tke arguement Lealue 23} pe, Out Yeguirement . . i : | xs SpUECH') ble should tre * Symbol MN bh | input craluey | one ¥ tod moles sputC % 4 uaud ~ Single space SpltC Atrualid ~empty space SpGECKY CAGE Le axes SPIO Split (‘10 thualid rat) PLE, EMSA spat crs) thuld 8 ce A, b.C = input (ela 3 Stvings +). spec) | print ([Link]) JMADGY Swe anetne mag tle qnwer HO) |- Te ts predefined function whichis wed & leak muttiple value, from were onuerG inte yequttueci clata type, aa: Syntans : Mop Lrequireal -methocl type, Walue, ). SputC) { Cos > AibiC = mop (float Anput(tenl& 3 Flot values’) spit Print (a) ( ~zubile a python code & veod 4 inlegey Ualuey using a single Gne Ob, Cy cl = rap Cint inputCenlea, 4 ‘integer Ualuey 2’). i ‘ . SpGEC ) eee pee : a) To Yead 4 ‘inkegey clalues §- print Cabove code) 6) To rad © sty Galuey, and print Sta, Sta, Sb3,Stu,sts =inputClenley s sti ngs + ). | ; spu lc | pant Csta,sta sts, Stu, StS) | Arbic = map(tloak input Clenlex 2 Plone stalues 21): Oub put: enle» § Se Kaul jyo. tam aghic onc Yama ‘isha OdvY + diffeverd Ualue, ancl print (art 9 kot Qo Yad ay bride, 9 * mopCeval input Clenley 1 different ualueys'). spate { prird Cilost a value, : ', rg) output 3 ae enley 1 clifferend CalueysI+25 34S) YtTR] 345ts} gag ursujy 34+4 last a values: atau) 3th dyini Haliae S differerct type of cole, using typed and print ad ualuey = CTrue, lo, ‘xan! a3-S, aa+u)) abcde = valuy, outputs print(a,biGs de) “Tue 10 kai a3-S 23tu) e) Read + compler value from user and printal) arbeder£,g = map Ceompley input (tenler thie + complex value, : '). spat) Print (1H complen Value ates, CcL.& Hg) luey print loxtand First Value] £) Read § boolean cla 0, %4, 8, = map Ceual, Input Clenley the = boolean ualues +!) spa to) : piint(*The first alues 42,'\n. the (ast ualue?) 9) Read s compler Ualues and print “tie sam 6 fay Abd, —mop Complex sinput Ctenl& the S complex ln craluey 3). Spat, [PYink Coth+ cede) ae ?) H)TO read 3 Float valugand print al Gneby | Une uaing Single paint ©) Spakoy) ree ia el ps ae A) Read 6 ckiffexent types OF uolues orc PHIM Gy, by Une : / ; map Ceua {input Col& 6 diffe, 0.1 Ag, A3,Fuy 1% $7.%G~ types of ceatues +) Spa bO) print CA, Ag, As, AyAg, AE» SEP ‘\n') Otukp EES 29 US Ty enler 6 clifferr® typey o Q le 6410} tka Fale e ¢ values Us-6 Tue C6Hoj) ‘Kaut Fals 7 . DRead s boolean ualuey ding ‘input Functiong & princbot o differents b= cual CinputCenley the poo Lualue -Y) cia. = wep Cewa, inpuk Clea the foo! ualues :)+ spate) de =nwap (eval, input (renl& tke bool odes). : ’ spt) print @b,t,d,e) : oukput 5 _ enter the bool Value + Trae onle. the bool cabs: Fabe Tue enlo. the bool Waluey: False False ue False Tue falge False. 2) Read Ss bey} Fidy nomey & prince Gs Re) 44, Sta, Sta Sty,St8 ~ MpulClenlex the ¥ best friends namey:').spli tO Sts enter “the eat fends nome; : padma kod ¥ ney NT mained RAT Visht honey marti ‘ a the cast of 6 Captopa and psint the tora cost OF & COPlPS t {,¢, f =mapCint input (t enter thie cost of 6 Caplops +! _SpGto) stat cost of & (aptope s atbectdtert) the cost of 6 Laptopa + Us00e 100000 60000 PO00D -$ $000 sp900 tal cost of © loptope + 380000 1 YO. 2026 Vile a pyiten code te tead yous NAME , COUYES NOME you mobile, Last 4 di i 8 name, cost oF Y fincade, colous of yous pen and print Fin mane and colour of your pn. ORY code , COUISE COL NUE, ely. name, sl_mobile , pi ncode , colo-pen= maple input (tenlex the name, COwiee ROME, Clg name, cost mobile, pincocle, per [Link] tc) U print C pi MAME , neode, Cou hane cold - pen) , J inpuk o'sty (0%) Nane,cou-name, clg- name ,colo- pen =Input(‘entey name, cou-rane, Clg name, colour of pens) Spite) cost, pincode = meapCing, inpuk Center the cost ancl : Pincde!"). spto) ; Print Cpincede, couname, Colo-per) outputs ish aa Mowe, Cou-hame,clg name, colors of per: blue CAE tke cask and pincode: as00 ASRS wee JONG blue Jou, Rn vceT x —bWe con print ory typ< prays in python ~The mast commonly : —f string (formated stving) fornia Caxguement Gst) aged Porrmacten Oe + stving Cformated Sting) -Irf we want to print an cwalue of a uaviable We can uge f-st%i -format -Tt should Stoxt with £2 prompt >" -And we should use place holders CX y) Th tg orp - th we want ntax should be paint Cf “east is cost 3") te print the ualue oF O Udvableg, ext a= int Cinput Crenl& the frst daxiable wale :') bs Int CinpukC'CnMlG the Secon variable value :5) pyink Cf" o talue Isfay bualue is Xby ") lite “a python code ‘te read firstand lastname | ond pfint a3 -folloog Fivst Name is + last nome is 3 Add Full name is: #-Nane, L_niowe = ‘input Crentey tre first and Lat Nome':").spatcy pint(F" Fiyst Name is : Pf-Names \h last name is r{Lnome 3 \n, And. Full name is: 5_ . ~7hlyite oa python code. ee ee “print “tke eure inleg ey W ues B—- eee TmapCink Input Clentey te st value 21) Spat) ae pantCf! me Sum 4s = Latbecedres) mde te read fiyst & Last name, i of mobile numbe, nn UW Ouy College’ » ayb,Crdye = ylyife o_ Python < 2 ication, Addvess, loat 4 lg ali antrestect or nok to jou enol TA, to output 0% Fallows C try tw we f- sting) Online Application Form Fiyst Nance : host mame Gualification Mobile lumboey rmoal id Ad des) a mriuling ts joinC V/A) * thank you: -! Format C axgurerment 8): : le can also uée O prectePined method fomnat), fo pint te walue of Syntan’ 77] nu oe \ point" zprompt >". format Caxquementa)) “We can algo we place holdeve in piornpt Go “aviable ex: aab= 10,20 print (‘The given value is Syand £4! forneot([Link]) araage & & noof placehold ake no-of arguement should be equal Oyb= 10,20 print( "ae i MG'O=s4 bas y oo g © PormatCarb))# inal q AF coje3 rhle canalgs use 1% Sa hae index talues of arquernent variable, Ext Q,b=1, 800 Paink(' the giver, value is Loy and 43" Fornuat(at)) lentes gh a= = thayeur ~ : one — We can also change ste -ordes of index uy, Place hoidere ex Ab =3,6 Pink (The given value 1s L414 204 T You", may Functiong : ) Ibis a cotlection of or gronp of stale ment ¢ Perform Q specific task Synton of defint a. function: def name~of the Functfon(arguements) « StatemenG ens def myname c) : print C' Kaci’) myname) Fyon te abowe example: MyNlame :nlame of the function Cusey clefined) feolon) . Stouti of indentofion PyIntOd 2 precefined function Kaui os Prompt Lstvingl text Noles While defining a function we should takecare About cndentatidy indentation means a& 4 emply space, from te Starting of the Gne ~ A function defini tian May contain: Any code of i¢ and n n0-of statements with proper indentation - tle can also clefine n noot funckiong ina Aingle piogsam Sgntaxs def -funcy: Statement ~ deb funtcrt Stolenenti def funnicd: ae eR RN it a “Fe we wank te execute afunctlon. statement we shatel call that funcklon wing Puunction Alame ¢ addcy 5 Hfunction clefinitton Pink (ath) 4hfunclian statement adc) H-Punetion calling ~hle can call any function any ro-of “times in pu program y ( ex: def ruc: print (‘hello mid) omic) te calling the ame Pun & times -Tt 16 highly vecoramencted ts define multiple single program te ‘increase Ihe functions “iné a performance of applications . —ulhile ct Firting functton in. python anguemenh Gs jona) a ean Find tre arguement Gist “in method! Sip lure tihot exacky a function should containg 4 Hhe vepeated| “eocle in OU program uge of functions ~nle can ‘wncreaxe performance oF Appl cation, ~ By cating our Yequived Puunctionys ~ ble can change the order of executions ~ By calling mulliple times in the same program eabonptes. : “0 J) wile a pytion code to define a function f yead 5 integey valuesancl print and erecule code def fiyellalueser? Ab, Le= nap CintinputClenle, 5 integer caluey:') » sputo) | Psint( P's integer waluer ave: fay aby, 8h, 8A9RG Pivettalueycy =P. 22... . _ | ET Me | anclip. 2 te define ? tanClion hivite a python cod wee ancl prin boolean i) ‘ ditfevent type oF UO def Ciffetalees ed: a=int Cinput('enl& Sint ualues: Y) b= Float Cin tenla float value 9) < = complex( input ‘entes complex calue ) d= tpt Cenlee stv value: € = evalCinputC 'ervléx boolean aolue 9) printf ' the boolean value 18 Jey 5 cliffuake, a > Define 3 functions one is to initialize S dy, Finsey tomes and print, the second should be iritil SF elemenli and unpack all elements ancl PYNk lot 2ualues only, thircl function should be to pink a Uatiable values wing Poimod -function §- exetuln, } { | def flowevsc): Fifarts tats = ‘ose’, ‘lotus, Jasmine, ‘Gli, : : ‘sunflower ' PIUNECF' The di€erent flower namey: §F,5 265 sf t def elementc>+ id teh) Values =[10, a0, True, 30.5, U0} Pans. t =Ualug printCf' @at avalue aye:$sh sey) def caluecy: O=20;b=as : PvintC’ the first ualue 4s$ Yard “the Second talue is 33 ‘formas ca.b)) Flowe vac) elementc) daluec) unite apyiton code to define 5 functiong fiyst function t reac 4 int value sprint side using multiple print - Function t yeact diffeyente type of values £2 ae — =k “A: Pad function empl) State menGe -fourtA function ead % initi A print Second cate se Adiffeverd Ualucy 4 S emply statement def veadIntc)? Aub, Od = MapCing input Clenlex 4 inleger caaluey,.") “spt c)) pine? gayend=* print ZF 563) end=" 9 prine CF '$ch Ld 5 Le5) Read Diff: Q, 109, 03,0485 = WopCeval, Input C'enley s. clitfevent ualues : "spa to) print £ © Diffexent type of ualues ave 20,5, {aah, fash, fay}, fa54)) de& ste: pass def Yeade> * A,b=20S True a complexCfnput Cellar int Cinpu ( lenle the inte pvint(f ‘The gecond ualue is 2 {by') the complex walue')) ge walue’)) de C4 ead IntC) Read DGC) yeolt) Stat ) Function Calting + | Neste Function calling: -TP we calk any function Aefini tion IMsidle anotke, Fonction definition, then hak concept treated a8 Inested function calling Ens a coger s COCO? def mic: clef M095 Print! iam my) pind CT osn mf mad de® maid: J def mans print¢ 'Tam 35 print (‘Tam ma") def ™aco4 del mao? moO age ri pyint('Lam ™3') print'T an >| ™Ms0d Ma): . | p Tunction with arguemenk s oy We can algo pay any type oF ualue b a We, waite defined -function from G Furictfon cact Fi Sendey 3 Function cal Receivers function defini tis, SRE def ™MIGabs ard ead value Bubside fun PeintCatk) function ™1Cl00,20) =H paying int dalue te functiondet » om. danckian col —7 Program & define a function ts print the Sum of “3 int valugy def sume): Ayb,C = mapCint, input Clenler 3 inle ger values : ').split QO) PANICLE Sum of aint caluey: Fay agHyHis | moO 2 inlege dalucy + 10 20 30 m of 2, inl value, 60 Besar ts define o Function to print diferent Calucy ypedtil CD ¢ Ualuey ~ [10/20, 2:5, 1otai,' sty} P2iv/S,t — Value, printf ‘different type Of Valuy:3P3 fy 2-5 Qotaj) types ; : Peve P f values > 10 86 9 output + diffevenk tyPE OF if piogiam ls define a function & print 5 dieferent p 7 of ualus giver by ugern tyPe def veer? : OL bode =mopCeual input Clenles diferent ’ “Ualue,’)-sputO) : pant(?' s different walues + Sab Shy 1b LASS) xe ty cralues and print First ualuey > pigien & tod <8 a Stt-laluec: gts, Sta, Sta,Stu, Sts = input telex the $ strings) - spbtoy pint CP "sta ) Str ualuesc) gutput enl& the 5 stein, rkouwi si son lokshrir yen kouti > Cefine 3 different functions 4-3 To plint Sum of nt value, a —> To print the different ae of uge, 3-9 Empty statement alae gi venty de® m)(a,b,0)* paint (fi the Sumof 3 values is + Aatht cy) def macs 11 110/20) 26) 0.4 ,09,03,0u AS =™ al, Inpub Cllenl& the sop CRN ditfeverd tyre of value sD Apot) 4 e pink ce! fait faay {ass avd fasy') >| def macd: Pass ¢ mac) outpuk the sum of 3value 18260 enlar the diffexerd type oF Calues ? a3 5-7 long Veaus! Tue . as St Clots) kos Tue ee 4y Define 4 functions one is to find and Pri sun, of Sint uolue, second function is & find ay L print Subtraction of three “umbers Rid function is fo4 multiplication and Ut onets Lox division and execule all methock Stale menly de® addO* 0 19,08 = MOP Cin, InputClenléy 3 ‘inleges Wah! . ~ sputoa) paintl? ‘the sum of Brinlegers : sartaasny) def sub0? by baba= nap Cink, inpub Cele 2 *mlegey values! . Spltc print(? ‘the Subtraction is : 3 bbe det mul? Cry Ca = Map (int, Inpetltenley the aimtegey values: ‘) spate) PANE CF \ Multiplication is 2IcpKCLy | def division: ie He) Fe dy = ink Cinpud Ctenlex the inleger value :') Ee da = float Cinpet Conles the £ foot ualue:) k fae svi = $Aytds)]23 ») Mua) diuision() Ouak pats enter 3 inleg® ualues + 30 20 10 the Sum of 3 inte gers ® 60 enle 3 integes ualuers 100 300 SO the Subtraction js - Iso the 2 integer ualuysus & 3 Qasy enley multiplication is enley “the integer Walue: Us- entey the float ualue + S-S~ Diision= &8-B5e! -@ Define 4 different yead 6 ualue and print wi del inttclueyc >: Ay 149, AB,AY ASAE = rad Cin function6 - Fach function should 2 ‘thin ‘the_ game functions Execulé all Function Satemen by catingonly one. fupction (nlested Punction calting) | tsinpetClenlathe 6 ualuey~ J. spu €0) print CP ‘The values ave = 725 780.85, 3035, Jays» Lass, 2063") I | def Floattialaes cr: by ba, b, by, bs be = MOP C 6 walueys!) Spa tO) Print (f' the Ualues ave= fbib {bad Xba Rbub A atialuesc def booltaluescos iwdtllaluesxo | Flo talues C> | C1102 )Ca, Cy, CS, Cg = MOpr float, input Cele the Loyd Ceb) | | | ceval, put Cenley the & boolean ‘aluey:') spat Pinte “he talue, are= Bary L045, ies FSh, Fee) | Syaluedt def styualuecys AyiMa,03,04 06,46 = INPut VOUS the. 6 Ualveys SpUEC) PUNK fF the stings Axe = Jar} 2Aah Wags Joy, fast 465") bool Values c> By Define a function te find “he Square ob tic giver, mambe . (read The Ualut FrOMN UCX)-ONA ere she code. def squayecd: Q=int (inpuk Clenley the number: ») eR print(f! The square of the given numbe= squoyec> Zoxay’) tug 4 Define a function b Find the Avg of three Nuambex®. 2 execulé code def Auge t oa,b= MapCF lak, input Center the three Walues +"). spG too) print(£' The ANG of three RUMbeg = $C Age ‘ ee -S> Define a function te caleatate the Aveo of 4 vectangle ancl execule cade de& areaty: length, wsidth =map (Float, input Clenl& the length andl wid th ualees :1.5pat9) prnte Area of “the *eclangle ‘is + Length! areal) width!) olps_ length and eictt® valug rig 12.0 venle. the 0 y rss 6— ee fe EEE Ayeo of the veclang le 48 2 1IWWO os 137.2026 NN Wile a prtton code to print AveaoPhoirgle def “Wangle CAvea): = Yeturn Area Print Ciriargle Cy 10% s)) COseB + def Aseaok “Wiang le ( Area): 0, b= MopChtoat input Center the length and byeodtth, ualues) spieC) OXeO. = O-SKAKS wo pine print (Area of tviang le) frend F-traltng (eC) cage.38 def Triangle Chength, breadth) + HAYea = OS® length, breadth yetu(n 0-S¥ lengtinxbreccith % Tictngle (asd) @v dengih, breadth = maplink,inpet Crente. the tergty and feadth ualues 1). spGtc) pxns(bvoinale( tength, breadth)» ~Sniile a python code to print the ualue, def Sumof-four Carb) * | geturn atbteced sumo Unk ae bey |] SY print Gunpt-fouy (arbi 4) Wile a pytion code to pink the producry 3 NE valuey ancl Sunt abd = edp Gn, inpet Crenle Te ‘inte ualues, to find Sum :[Link] def — ReductandSum(n1,nana)z Yeturn na tnatns, nienadng Me PaiMs = map Cinksinput Clenl& 3 Valuey tp find sum and product 2D split A print (the gum and product are ', Product andsy print(Roduc dSum (rn Ma,ne)e Crum") Oukpubs va \ enley “2 value, to find Surmand products ty The Sum and pwduct aes Ce ¢ an Cs, 6) From He above example we are Yeterning li laluey One is:Sum, anothe One 43 Produc tthe Yeaull eail( be tuple -format- oudpu —Tf you want to Pring individual veguth you nee & take & different Naviable, Ahi Le yeti” the Yetuin alae WNife Q Pytion code to print the Bum ,dittat Product of five ‘integer Valiny ° def — Bum-Frod_dief Co NUM Ne, Ay, AS) 2 Sum = Niet ARAN MAS SEP = ~~ ny Pod = eX Ng x DANGXNS- Vetuin Sum, diel, Plod My Nos NyNs = Map Gnt ,inpud Cenle.s mle Ve talues +o Find sum, dite; products!) cpt) ee Wl Tadd sab mal = SPEDE MMM | ‘add, sub raul = Sam- POd-PFC M My hs) printCAdd Sub,mul, SeP=! a) —s Wile a python code to print @ COMPMSK. and Sting va del — complexandSts (St) + a vetumn a,Sth LO a= complexCinput Clenl& complex calues)) S4= inpetClenle sty wlues') CA, SA = Complexandsty Casta © print CL complex value iss {eay, Stving ualue y “as ¢3a8.) Livite a python code a print your Td, name, branch , clgname ,roon nu, Bus NO def details Cid, name. Branch,Crane, ¥-nu, BNO)? yetuin “id, name, Branch, C-name, TNL BNO 4d, [Link], Bus-n0 = wapCint. input C' enley He id yor number, Bgnumber 5) put) rome,branch, clgnome. = ‘input Cenl& the name, - branch, Cg name : ') .sputO = details Cid, yoo ™Mnu, Bus-no, name, branch clgrame) 2 pant?! id= gay ion-n AibCidverF = detarsCid nose, ab cel, e byanch, clgnane, Yoon | nu, Bus-7) plint(2lfd=gai name= {bs branch= 3ch | elgrame=Sdy vemno= 2e5 gusro~ tf") | | Function wort Qiquement- 2-A011R yolayn yah il Sak TT To pe 9 We con ako Written any dels ition oi Sed rat . seerrand Jats, roe need! rover only mera ot a time ons CAs ang ms Gint® ant mi Cink O, nth ? 1 8 yeturn a5 Jl ualid ~ vetuir Asbic 5 3 4 ee? nk my Cink oink binto) g Yetumn abt? I] Valid : Uabus, — Buk in python We GN sovitlen muUckiple CMe by af OO tine ty uanng comna Cs) nshich is kenooPy Bepawalor of ex Tetum abc» Yeturn 10,'indlial los +#ualtd —iTt ie aloay recommended £0 Year (ralse from function ele fini Gon = bbe can print directly the retumvalie or Cabs €x+ pvintCms e ae pe 4@,b)) | divect Prinkirg shWecan abo stove that walue In q temparony Uariable ancl prink Yex = M4 Cab) prin (aed) — Tt 1s ahoayy vecommend... bs wae stoving the yetum walue inatemp Loviable .it-that® funckiondl velian mutiiple valeurs Tt that function det return, only one Value’ then ‘yecormmended te pink directly without end Noe. Vanioble |

You might also like