You are on page 1of 21
Sub Code: 22PLCISB Textbook 1+ Chapters {-3, a asian: tale Lb. tolesachive Shell. i aki Pg. No. Dept: VBL, AP, Dept of ECE, MITT eee Subs Sub Code : Math Operators from Wighest bo dowest Precederve.. Operator Operation Example Evaluates t0--= ¥* Exponent BK RS 8g % Modulus /Remaindey gave @ 6 u [ fake Diinten/fiegr aa] 8 a Division 3a/g art Multiplication 3x S 1S Subtraction S22 3 + Addition. eth 0 The order of operations 4 Python’ ‘matt Operators Is Similar to thal ef mathematice, Farantheses con be used fo overnidle Mie usual precedence . leq i=» B+ 3 *6 20 v yr (ate 30 ¥ p> 6+ Invalid Syntax , yp atannd Invalid Syntay . Dept : + pa-no.[0 lo ][ 2] Sub Code: oO, *) +9 rhs, 00, 6S, +27. 1 _eq= ‘Hello!’ , ' 10 Swang' .-- : Goodbye , nn or ~ gunte or double isnle blank sting or _an_empty Sheng 16 also altoweel. | fue Shing eg I- Dept »> ‘pil ‘+ "hfe » Wild + 2 Sysntne Avie Pg. No. | © 10 Sub Code: Sub: Shing Rplication Is fhe gperation perforrned b ouphicl ale Ma genn Shing for an integer Value mentroned. Shing vepltcation speraler ds (HH), eg! » ! Orange’ ¥3 Orange Orange Orange v bad ‘Orange! | Rec’ x Typeérror + cant maalleply Squsnes by Non -int of type ‘sly. » pple’ 2.0 Traceback (most recent call last). Typeermr: can't muluply Savence by fon-inl oF type ‘flood, Storing Values in Variables A voviabk ao kk a box In CG compullixs memory whrL a Single valus an he ef thu Cvalunted crpression can be stored x Sloved Result fnside a vertabh = for tutte sage. Assignmced slalement consiats af a variable mame and dquo fiqn ') and Um valus to be shred. Ar eq te numbers ae ae { \ . Variable Na Volus {> be stored. numba] Assignment eperater Po.no.[§][0 |L4] Dept: Sub Coda : fq!- 0 >>> Num] = 110 >> Num 40 » Num)_= 40 — Vour fics! Leguasn | Develop program te read and —dinplos}— ‘fla —nnens “E oy more ") * name = —Inpwt fot oa Enter_yous brands nonch > __fnpat 0 | pict Css yous tea an) | sslage = pat Sub: Sub Code : Ece Morr Develop o—pingrom do find orca of a circle sectongle ond _dioplay ¢fin sresett int ("Eaten radia) = floc ( input o) Lprint (# fntex fenqua ") po = int ( inpwrO) fs (* Ealer taidtis") w= int ( fnpw o) Acs ax 3tus ¥ (¥xK2) Ar- fxw print _(" Aco of Circle", Ae) [prod CY Arca of veclornle” » Ar) oukput + >>> Enter rads 2 Dept : Pq.No. [© ]L° ][6 "Sub: wbCodo: ul Sub Codo : de> Enter length s po Enter Wide 2 go> Area of Civcle 25132 pra of yectarde 1o Dissecleng — Preqrarn . *) Commenk ? Rython Ignores commen =) cormminb Gan be wsied to write neler or Yemind abou Uae cede trying te do. +] programmers coil! pul a commenting ojerclor tafront of a ne af coeds to kempovarily vemove WH uslile esting la program - Thin & called * emmentiog. out” tode - Cornment in oyeratos cam be vemoed eshin Ge prapramerey ead bo pr Ue Lert back tm. Yhon also ignores dhe bank 7 con add many blank ne ae a oe want > to make code easter to wad, Uke poragraphs in a book - */) The Pint Function: The print funckon ited the shing valu inside fs porenthess on tas eine, eq'- Paint C Helle , world") pant ("whol to your nome?" ) eis Dept : Pg.no. | O]] 0 [7 eg: name = fmpuk ©) * | Thie fuunckton call _evaluatea doa _shitng equal to Uris | jwasex’s desl ond ths _Ifne of rode _auaiqna tris name. Variable to _diats. chitng, yolue ashing G func funckion —evaluoles dots tnleqes value of tris sumer of | chavackeyve fn__Liat shina, feq:_pwtnl_¢ * “Ihe Jeng th ef —youx_nowne Iss") + Ss yr len Cimy energy ts inexcasing day by_doy*) xe se_ In) 0 *| The sh O_,_ foto and__4inat ()__funchions: “The _shring intsqr__and___flaabting —pe! Gi é ro int loot) yeapeektvely » Levoluoted hy strt) int t) § float __vep + Po.no [0 J[0 || & ° Dept Sub Code : Sub: tqiy ser CAD "14 wr print (71 am’ 4° gtx(29) +. ' years old.) foam 24 yers old. my int (42) he dy int (1.99) 1 >> Ploat +3.1h') 3.4 Sy float (1) loro +[ into, fleakO , 8&0 functions can be ured bo gee o value of the appropriate dala type for the cod —_ se Dept: Pg. No. [0 Sub: Sub Code : |_nomly Tae and Filer Like any _olhex value, Goolean |—valirs axe used _th__expyessfons and can be _cloved fn variables legs 3 Spam = Tri Not Equal fo ‘ less than False > Grealey than yw 9123 Se lus than ov egal to True é= 1 raler Vhan ov equal bo] >> 22 Falte _| Dept: P9.no.(O]Lt |Lo Sub: eal Sub Code: lean Operators: Thee ave three Boolean cporators . are? and , or, not, which art used bo Compare Boolean Valin. [ke comparison Bperators they evaluate (hece epremstonn advan +2 a Boolean value - and Operator % oF opoaler * pot Ofer True ond Tue Truc ov True True and False Truc or fale Fol ov tue Tala or false Fale and falte and operator ° Expruston > evalualed to Tue when all te Inpuls an Tru othiwite the output ail! be Falee- ov operakoy : Expreion & evaluaked to Falke whin all the inped, cou False Otherwite the output tu Tue. rot operator * not operon operate. on only one Boolean value Tha makn it a ~wnaTy Gperakor The not optrator Sengy evalualiy 4p the opposite Ecoleam value gq >> Tuc and false false > false or False false p> Not Trae False. Dept : Pg.No.LO]L I]t ae Sub Code: ap KS) and _¢(s<6) Truc sr (465) and (946) false yy Che22)0 or (222 20 Thue yyy east hand not Axdess 2t2 Pg. No. [© Sub : Sub Code: Truc or Foltee, and alrnost every flow contra - Slalimunt Wer a condition. Blocks of Code: Lines of python vode con be grouped together in Gocks - You can tell cohen a block begins ord ends from the indmlation of the Lines of code. There ove diree rule, efor blocks ' +] Blods begin whin Lae . indentation increases contain OlGsr blocks. indenlakon indentakion. «| Blocks can +] Blods end when the decreann bo xvo oF to a containing block's Iq'- name = ‘Manu! Posword = ‘Soord{ish' if name == manu! + pret (' Hallo, Monn’ ) if pomusord == ® Sued feeh! « pant C! Acces granted! d else : pret Co bony poosvorrd |) Progra Execution » Ry thon Program execution : The program term for the current Instruction being executed. execution Not all programs evecud by simnply ging Shaight down , however. If we ate our finger to frac Ahveugh a froqram with flow control Stokemenbs , we will Ukely fend yoursell dhe Source cade based on conditions and gamptng oak ese, probably skip entive dare. Dept : Pp.vo. LOLS J ti io} a vi i) Statements: ‘Sub Code: Ly tusing — expressions dhat levalunte 4p “Fn. or false ( also called conditions) , tae if Hoternts else Sintimnts elif statznunts while ctafmnts. for ___ Stalaments break slalements Cenlinwe _cialermmnts |Stabemend is tts if oil exccerte if A Condition A__colon Statin Dopt : i{_stolemmdis ; The _mosi_ common lin shipped if (i comilitiom > alee fin it_sh + | dhe if Veyrsord ‘ Pg. No on the next Une ,an indented block of Code (if clan) oh] iy Sub: Sub Code : eqr if name == ' prince! : print (THE, prince 2) The flow chard fr an if Gakement - else Statement An Yo clause can optionally be followed by an cle statement. “The elec clause is execukd only when b fale. An else daternent the f{ stakemenl’s condition In code an else stakement does!) have a condition + and cons of ie follouing , y o] the ce Kexyeoord «| A wlon «| Sloting on tr met line, an trdlented block of code called clse clanee- Start eq if name == ' prince’: mt (hati Qrtat!) Far Tous pat KE . pre (hat + Ort Spend Te else: ‘ print (1 aello, hanger) Fale J Sagi Pint strong’ énd Pg.No.[O ILI |S Dept: Sub Codo : if name == ‘Alice’: print LIKE, Ae") elif age <1 prot_( ‘Youare not Alice , kid," ) Dept: Pp. No. Sub: Sub Code: While Loop Slaterments > We can make a block code execacke ocr and oxy agaln using colle — Stalroenifs ond tion ot Tres Ho comtish Of +] The chile keysoord . A conckition =] A colon . Starting on Ve next Gene 1 am sndented block ef code. i ji just The hile claux often cated Phe whale leop 7 4 tre bop , Spore = 8° thikSpam <5 * : pnt (h nete eotd > spor - Spam +) Tot Print (‘ello werld ! Dept : P9.no. LO Jt [7 | Sub: ub: Sub Code : ent Ahr execution venches o _brsak _sindement id Limmediody exits to. leap clause In coeds x fase Simply contains the break Keycood eq.- _tabile Thus + psini(* Please hype ayeux narne ") nome = _‘inpato H_nams_= = ‘4a name’ t freak point‘ thank youl"? | ctntamnenls ~ axe ised ‘inside loops - tohen_O_pregramn i isnneds Jurnps bach te ¢m, _sbaxt of (Ga eq.= toile Truc: pint (whe ove you 2! > name = mp) ig_nam« |= | Joe! + _fontinue mint ('itello, Joe what ia _qanword 7) posssord 2 Input O “[_punword = = ' Ssordfish’ + break print (' Acum granted) Dept: Pg.No. LO JLUE Sub: Sub Code : Leaps = tocping usb is tndition & Tr» bul if we wont qo exrcale aq block of code only a cevlain numbey of Himes, tse can do Hd Usith a for loop stolkment and rorye fandion. 1 consists of The for bey word - 7| A vaviabl nome - | The ib kayesord . A call bw MH My O method up fo three jnteqers paused wil +] & clon. Slavting °° Hoe nent Ure san Indie Hock 9 code - i fotal =o for nin Yang (tov): Intal= total + 9 print Cetat "> tetst) —4 prot ("iy pet nome u") namt + inp o for i in yang (9)! print «" My pet name nj name) Dept: Sub: Sub Code : abasic’ cob functions called built of o in_funchions pinched ues pink tng ty and [ent firnebiena in comes sith a : . Skowdavd Libvary , fark. nandute in poy Lio fusqenmn | foal __connins a lobed goup of anshiona Lisa] can ho trebedded tm uy _brogvanas v e9'- math mecute has mathemalics relate! funchons. yardlom matule har vandom number related funckions. and $0 on + | Before wae can ise the funclions in a nodule , soe must TThe_twaport__kayword The nome of ts module. Optionally more _modubs narner » o fong a» tray are Sepraked by commas - + Jo__frint_randorn number for tim vange (s) + import yandoon Gulput +f ! frie Crandom - vandint C1, 10) 8 q J ! Dept: pane 1212 | Sub : Sub Code : An alternatéve form of the Import stalennent 2) Method 2: —o Is amposed of the following » “| hor Kagusovel followed by module core Import keyword and g star. eq '- fromm random Import * totth this form of impor! Stakement , calls to funckions In randorn will net need the yandorm + prefix « *] Ending a program Early with the Sp. tO Function Program always Jerrninate if the progvarn execution veaches the totlom of the “mshuckions Wouever , We can caste the program te fereninate or exit , before the last inthackion - by calling the Sy.exitO function. eq import Sp: while Tome + print (Hype et’ fe exit") Yesponse = inpuk Hy cusporm == Nexit! : sys. exit O pent ("You typed + response ¥ ‘to exit!)

You might also like