Python Manual

You might also like

Download as pdf
Download as pdf
You are on page 1of 105
COMPUTER GROUP | SEMESTER - VI | DIPLOMA IN ENGINEERING AND TECHNOLOGY A LABORATORY MANUAL FOR PROGRAMMING WITH PYTHON (22616) 6 i\ddddde SO TTINANE ASHLEE SHVU=H=TO) No pate NT CeVeL Ue CoA TUF (Autonomous) (ISO 9001; 2015) (ISO/IEC 27001: 2013) Scanned with CamScanner Programming with Python (22616) VIIL Resources required Sr. Name of Specification Quantity | Remarks No.| Resource (ifany) 1. | Computer System | Computer (3-15 ‘As per Batch | For ALL preferable RAM>2GB) _| Size Experiments 2. | Operating System _| Windows/Linux 3. | Development Pyhton IDE Software IX. Resources used (Additional) Sr. Name of Specification Quantity” [| Remarks No. | __Resource If an; . = _ (fany) 1._| Computer System mabe Operating System | igindows U1 : Development Softwoe Python IDE X. Practical related Questions Note: Below given are few sample questions for reference. Teachers must design ‘more such questions to ensure the achievement of identified CO. Write steps for installing Python on window. State IDLE in Python List key features of Python Explain Python Path State use of pep and pip BERNE (Space for answers) 4 Sep 12 Seecd version of pythan do tasdau sep 2 Yownload python Lstecedable installer steps Run Lxeculable tasdauen. Maharashira Sate Board ef Technical Education 6 Scanned with CamScanner Programming with Python (22616) step ws Verify python oi stalled on windows wheps 8 Verify pip wai inahalled giep6 8 eld python path onmen} Step t3 Tnsiell vintualou . LEDLE ts pythen's Integraled | clevelopment Envircoment TY allows pragnammens to corite python code. Just Stike™ python chell, TyLe can be wed to execede a singk statement and” pater ome: Romie " ves aj fosy fo dean Emeresive language. ~Entenpreted lanquage “Ghoss plallorm janguage “=fnee and open source object — oriented” Janguag —lorge standard “Library.” if Bythonpadh “is eo” envireament “ontable “chich fhe User “can 6b yo add addition al ane Ctontes that phe “User” wanls python to. ya de tne sus a 2S Pee 7 [PEP “proposes thad dhe” Installing” pythor guide be” updaied “Fo officially 7 of PIP as the delault install sy thon po eKa eS redhe than the curren! approach ef cecommending “the “elirecd Foveralion, of “phe step py, comconcl » odudes use ‘Maharashira State Board of Technical Education Scanned with CamScanner Programming with Python (22616) XL Exercise (Use blank space for answers or attach more pages if needed) 1. Print the version of Python 2. Write steps to be followed to load Python interpreter in windows (Space for answers) import sy 5 pcind Cpythan. version 8") sys.vension ) zg 44 Following” ane Sheps” yo he” Followed” 40 ‘Youd pyjhon inkerprden fa windows oo” WY Open system propenhies - 2) Click on advanced system seliings in the Sidebar 3) Click Envinonmentol variables = a) Selee# PATA in the “system variable section sy Click” on edit 6 Reply python podh to the end ot the ist.” ‘Maharashira State Board of Technical Education 4 dd iidddddddd \ «on GRO ONS ddddd 27229 Lis A é Ls 20? did 2 eee a a a2 ae el? sla © be aw Scanned with CamScanner PEGEELESLLDDD ede fy f oe oeveuvees f ee / PPP Ppp ooo € References / Suggestions for further Reading https /iwww youtube com/watch?v=eV-vluunPjL 1 2 2 3 4. https www youtube com/watch?v=N9jTIPt_xu8 XIII Assessment Scheme https /;www howtogeek com/197947/how-to-install-Python-on-windows! https /www ics uci edu~pattis/common handouts/Pythoneclipsejava/Python him https: //www maketecheasier com’set-up-Python-windows 0/ [ Marks Obtained sss Related | Product Related | Total (50) ‘Miluraslira State Bourd of Techical Education Scanned with CamScanner Programming with Python (22616) Practical No. W Vv. v. vi. vil. : Write simple Python program to display message on sereen Practical Significance Python is a high level language which is trending in recent past. To make it more user friendly developers of Python made sure that it can have two modes Viz. Interactive mode and Script Mode. The Script mode is also known as normal mode and uses scripted and finished .py files which are run on interpreter whereas interactive mode supports command line shells. Students will able to understand how to run programs using Interactive and Script mode. Relevant Program Outcomes (POs) * Basic knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to solve the broad-based Computer engineering problem. © Discipline knowledge: Apply Computer engineering discipline - specific knowledge to solve core computer engineering related problems Experiments and practice: Plan to perform experiments and practices to use the results to solve broad-based Computer engineering problems. Engineering tools: Apply relevant Computer technologies and tools with an understanding of the imitations. Life-tong learning: Engage in independent and life-long learning activities in the context of technological changes in the Computer engineering field and allied industry. Competency and Practical Skills Develop general purpose programming using Python to solve problem ‘The practical is expected to develop the following skills: 1. Write a simple Python Program using Interactive mode. 2. Write a simple Python Program using Script mode. Relevant Course Outcome(s) Display message on screen using Python seript on IDE. Practical Outcome (PrOs) Write simple Python program to display message on screen Relevant Affective Domain related Outcome(s) 1. Follow safety practices 2. Demonstrate working as a leader / team member. 3. Followethical practices Minimum Theoretical Background Different modes for executing Python program. Interactive Mode Programming Invoking the interpreter without passing a script file as a parameter brings up the following prompt ~ $ Python Python 2.4.3 (#1, Nov 1] 2010, 13:34:43) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 ‘Type help", “copyright”, "credits" or “license” for more information DBD ‘Maharashira Sate Board of Technical Edveation| Scanned with CamScanner Programming with Python (22616) ‘Type the following text at the Python prompt and press the Enter ~ Hello, Python!" ‘new version of Python, then you would need to use print statement with parenth 1 print ("Hello, Python!"); However, in Python version 2.4.3, this produces the following result: Hello, Python! Script Mode Programming Invoking the interpreter with a script parameter begins execution of the script and continues until the script is finished. When the script is finshed, the interpreter is ro ~_[Roqnam Cole $= OSS “Print C Weleome Jo python ") | sd test py file —Oulpeal = Now, try to —_|___ Weléeme to pyhons fs es “T Remarks No. | Resource (ifany) T. | Computer System | Computer (3-i5 ‘As per Batch | For ALL | preferable RAM>2GB) _| Size Experiments | Z._| Operating System _| Windows/Linux 7] 3. | Development Pyhton IDE Software IX. Resources used (Additional) Sr. Name of Specification Quantity | Remarks No, | __Resource os mee 1 [Computer System [CSR nal 2 [Operating System | windows |, y 3. | Development Dython 1 Software | Python TOE | ‘Maharashira State Board of Technical Fducation Scanned with CamScanner Programming with Python (22616) X. Practical related Questions . Non Below given are few sample questions for reference, Teachers must design more such questions to ensure the achievement of identified CO. 1. List different modes of Programming in Python 2 Describe procedure to execute program using Interactive Mode 3. State the steps involved in executing the program using Seript Mode 4. State the procedure to make file executable (Space for answers) on paogromm tog - stedement” into paompt Cod on S55 yond” ein ail gett Z]e9o. to File 4} creode newhile or press Chal + de Jour | script | code ~ uy is Add O shebang dine to the top” Hl [dae Tin lene pathos ep. iain TE cect a ees “scripl mame: p © pdd the “alin” Nari ? to your pedh Lpedh Piel scalp) 3 dpm ey ‘oharashira State Board of Technical Education Scanned with CamScanner Programming with Python (22616) XL Exercise Note: Faculty must ensure that every group of students use different input value. (Use blank space for answers or attach more pages if needed) 1. Write a Python program to display your name using Interactive Mode 2. Write a Python program to display “MSBTE” using Script Mode (Space for answers) SSS prind Cyour name ") Louk pud | §- Year, O.omre pata 0s BFE*) Oud ped ee CB TE. 7 Maharashiva State Board of Technical > | Scanned with CamScanner Programming with Python 616) Arithmetic Practical No. 3: Write simple Python program using operate Operators, Logical Operators, Bitwise Operators I. Practical Significance Operators are used to perform operations on values and variables, Operators ean manipulate individual items and returns a result. The data items are referred as operands or arguments. Operators are either represented by keywords or special characters, Here are the types of operators supported by Python: Arithmetic Operators Assignment Operators Relational or Comparison Operators Logical Operators Bitwise Operators Identity Operators ‘Membership Operators Students will be able to use various operators to check the condition and get appropriate result by performing different operation with the help of supported ‘operators, I Relevant Program Outcomes (POs) «Basic knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to solve the broad-based Computer engineering problem + Discipline knowledge: Apply Computer engineering discipline - specific knowledge to solve core computer engineering related problems © Experiments and practice: Plan to perform experiments and practices to use the results to solve broad-based Computer engineering problems. «Individual and team work: Function effectively as a leader and team member in diverse/ multidisciplinary teams. «© Life-long learning: Engage in indepet context of technological changes in t industry. indent and life-long learning activities in the the Computer engineering field and allied IL. Competency and Practical Skills Develop general purpose programming using Python to solve problem ‘The practical is expected to develop the following skills: © Write a program to use Arithmetic, Logical and Bitwise Operators IV. Relevant Course Outcome(s) Develop Python program to demonstrate use of Operators V. Practical Outcomes(PrOs) Develop Python program using operators: Arithmetic Oper Bitwise Operators ators, Logical Operators, related Outcome(s) Relevant Affective Doma 1. Follow safety practices 2. Demonstrate working as a leader / a team member. 3. Follow ethical practices eee ——_* Fratarashra State Board of Technical Bdueation Scanned with CamScanner be 3 Programming with Python (22616) - ¥ L inh _ if Teft iby the number of bits specified L__ ] Po 7 = E Code % Remarks | 2 Jee tam _| ;3 TE Arithmetic Operator ~ = —_ 5 — a) ° n2z= 10 ~ Sume ni tne a > min =N1- 02d 2 mul = nt *n2 than 0 > din = float (n") | Float Caz) iamincciCe) > print (OAddifion is” 1 sum) 5 paint CSabstraction is” , min) oe Li peint Cull phicatton is", mut) ee a print © Division 15") div) ———— x HE pilwise Operator —_—__——_—- y a= 10 a ~ be 4 ——_—— . 4 print Ca®h =" ahh) ———_ 2 [print Walbh = "5 ath) aa ie print (na =" )na) ee 4 print Wanh=™ 4 arb) —— M5, a __ — Ls FE bogicol Operalon ; . 3 ——) a=5 ° a 3 b=10 ee w 3 c= 5 od 5 er Scanned with CamScanner fF b Programming with Python (22616) shift left by the number of bits by the right operand, | | VIII. Resources required Sr. Name of Specificati specification No |__Resowce__|_SPSAWon [usr Roars i ft a>O and bY O print C' The numbers ane greater than 0” if as0 and bdO and os03% print C' The numbers ane greater than 0”) else print" AHeast one number is not greater than 0") OudouFt 3— Addition jis 1 substeactian Mulliplicaton 16 Division 1S 0S agyb = 0 = alb = 14 mais -l) ae anh =14 The numbers are greater than © Aileost one number is not gnecder than O 7 Maharashtra State Board of Technical Education Scanned with CamScanner snming with Python (22616) post shit Tefi by the number o by the right operand : aL ] J Resources required yl. y Name of Resource Quantit; Computer System ; —_ ‘on * preferable RAM>2GI As per Batch |For ALL | Operating System | Windows/Linux GB) _ Size Experiments | Development Pyhton IDE | Software | 1x. Resources used (Additional) Sr. | Name of Resour‘ ificati —- No. nee aS Quantity [ Remarks | y+ Computer System 2S “Rani (ifany) | 2._| Operating System Windows 3._| Development \ Sawer Pycharm IDe X. Practical related Questions 1 must design Noter Below given are few sample qiestions for reference Teache! more such questions to ensure the achievement of identified CO. 1 Mention the use of //, **, % operator in Python 2 Describe temary operator in Python F Deseribe about different Logical operators in Python with appropriate examples 4 Describe about different Arithmetic operators in Python with appropriate examples ' 5. Desenbe about different Bitwise operators 1" Pytho (Space for answers) sn with appropriate examples toy 8 Fioor | olivis fon pelurns ¢ ! jre decimal ICFicge” division) 8 ieee Ee ar fs Quefien! fa which he “eligi otN ane Refecled” ta The 0d spi He A thammant) Gas opecele eee 4 a ee erties enpanential Calculation aie ~™ ; > . athe ‘le Cocudus )% “ep lures o Met tbh oe we eeeipe set) Oe aividing “andl « Spe nigh oe 7 Scanned with CamScanner Programming with Python (22616) —_(Subieac fon) Subiea ¢} igh} operand - deft operand ¥ Cully plicedt C LUD ston 5 ivivide del operand “by ipe PHY operced ‘Ie Cetedulas 3 Moddus reminder of jhe of teh operand by hen tghy [floor division ¢ SE eeltnns dhe Quolten) the cligts “alien elect reel porn 3 The Jeff" opercind is Pale, right. Scanned with CamScanner Programming with Python (22616) Exercis 3) tinpor+ math __ __ Ss ° Bitwise operotors act on operands Hf they were a string of binary oligits , these operador performs actions bit by bid. © Let w= 10 [ooo 1010) ancl y= 4 (ooo oloo) in the —— heloa table operator] meaning i Exomple 1 = — — g Gilwise AVD HRY =0(0000 coo ) —_ | —- 1 T gHwise OR Tol Y= 14000 bia 0) — yTo«~ Bitwoise NOT wx =-1(itl olol) _ | — n Tarkatse XOR mAY = 14 (G000 1110) — >> Bilwise right YYZ = 2 (ooo 0010) a shift TS a 8 e-s print ( positive number "’) —< elif num ==0 8 a ins print ("Zero") 5 - ele — print (" wegadive number ay Ss [ae rested iH statement alee oO fe2 13 a) sf Cis ee i 6-3 if C¢ : ee SL Print OTe is_smallen thon ie | TFG 412) 3 = pr atl Ys is omaller Yan rm") i ° . 5 Sal Cig is _greader than 12") _ | Te Scanned with CamScanner Programming with Python (22616) VIIL_Resources required ~—_ Sr] Name of Speci No. Resource | cation Quantity |" Remarks 1. | Computer System Computer (3-15) As per B Af an: per Batch | For ALL _| preferable RAM>2G 2 [Operating System_| Windows/L inure iB) _| Size Experiment Development | Pyhton IDE dudtome 8— um mar {if any) _ b bis greater than a postive umber i is smaUer than 15 t is gredder than 12 chers mus “(Space for answers) a i] There ore 2 opercdors ane used Mm 7 ey Relatio Co mpanision shodement Au Condilians vast be when o Gey _lieted / MS frag then the mean Veonelflfans are ay none } plex fr] giadement [a)TE TS eo" isa’ sioopile Scanned with CamScanner pr Computer System Computer (345 referab| [Operating System | WingoseME2G0) | ¢ Development Pyhton IDE aa Software Jx.__ Resources used (Additional) Sr] Name of Specification — No.| __ Resource Quantity [Remarks ) 1._[ Computer System_|ComMPatepn— t=s-- (If any) 2. | Operating System | yo edo Ws 3. | Development Software “Pychanmy X. Practical related Questions Note: Below given are few reference. Teachers must design more such questions to ensure the achievement of identified CO, 1. List operators used in if conditional statement 2. Differentiate between if-else and nested-if statement sample questions for (Space for answers) a ve i] There are 2 opercdors ane used ih If conditional stcdem TY Reladioa & Componision operaton ihegiesl apr qi shedemend 1 eter 3c IAN conditions must be = When a dogical dee ae Hesiod” ™ he"Ymue then the remaining i ondiifans “ane 99 P00 e cl. Stalemen} RTT TS “comp ke fea ) cera Ves Vs ane feste lita condi}tong mual be fijslalements orc eee sted go ts" a" tae lunlil the ¢ oS ce 2 — ; PEs nol 4 Consuming process jrue 50 Feansumiag PAC Scanned with CamScanner Programming with Python (22616) XL Exercise Note: Faculty must ensure that every group of students use different input value. (Use blank space for answers or attach more pages if needed) Write a program to check whether a number is even or odd Write a program to find out absolute value of an input number Write a program to check the largest number among the three numbers Write a program to check if the input year is a leap year of not Write a program to check if'a Number is Positive, Negative or Zero Write a program that takes the marks of 5 subjects and displays the grade. avaene OES King whe PRET HENNE yer te: ever on odd”) no= in¥ Cinpud CENen Weimber Sipe bd er Wumben $3} numb en Js odd” aoc CFinding the oh solide Value of the number”) stab Gnped CE er Numb ag Y yy Cotad ; jafe’ of "90," =" abs (no) ) Outpud © : ; : nding the “ebsolwWe “value of The num ber Ede Gurmoher 4-8 Bhsolule value of -g = § val yeni CF inding darges} “lumber among Meee slumb e*) Tad Ginpud (baler 154 evo % ")) a n= tal Uinpal(’ Enter roel co & ")) nd = 4a) (inp CBnier 3nd Wot ")) HU onrynz and n> 038 io CIsh 90 Fs dargesh")* af n2yo) and [Ory 043 + Scanned with CamScanner Programming with Python (22616) oo peint ("Ind Wo is gf tot ("check the number #5 postive ,negative or zero") n=intinputl' Enter wos") ) tf n==0 3 print("Aumber is zero") 5 enya s print (“cunber ts posrfive”); else 2 print’ WNamber Ts Wegasive | Oudped $= Check Pf the number ts postive, negabive on 2er0. Enter Wo 2 22 lumber is positive G] PrInF CDisplaying the grades ") prrot Enter marks of the Following subjects ”) moth = float Cnpat CU todh § "JJ C = Floot (TApat ("03 ")) jova = float input (" java 3")) python = Flood Gnpud (" Python 3") ape = Ploot(inpuk U Cpp $"")) ovy = (math +¢ + fava+ python + Cpe) / 5 print C'Average =", avg) iFeavg {= 100 and avy >= 45 eeint(" Grade = Distinction ") dif avg LtG and wj >= 6° 8 print(’ Grade = first closs ”) Scanned with CamScanner Programming with Python (22616) difevg < 60 and avg>= 4o 8 print" Grade = poss class") elif savy £40 and avg 20 print(™ Sorry you are fail “) else & print (* Invalid marks”) Snot") Output 3- Displaying the grades Enter marks of the Following subjects Cath & 99 c 299 jove 8 95 python 8 99 cep 8 99 Average = JJ-0 Geade = Dishinctton. Scanned with CamScanner rogaine Python (22616) por Sa Heap ye Programming with Python (22616) Practical No. 5: Write Python program to demonstrate use of looping statements: ‘while’ loop, ‘for’ loop and Nested loop 1. Practical Significance While developing a computer application one need to identify all possible situation One situation is to repeat execution of certain code block/ line of code. Such situation can be taken care by looping system. Like all other high level programming, languaze, supports all loop structure. To keep a computer doing useful work we ion, looping back over the same block of code again and again. This practical will describe the different kinds of loops in Python. I Relevant Program Outcomes (POs) * Basic knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to solve the broad-based Computer engineering problem. * Discipline knowledge: Apply Computer engineering discipline - specific knowledge to solve core computer engineering related problems + Experiments and practice: Plan to perform experiments and practices to use the results to solve broad-based Computer engineering problems, Engineering tools: Apply relevant Computer technologies and tools with an understanding of the limitations. © Environment and sustainability: Apply Computer engineering solutions also for sustainable development practices in societal and environmental contexts and demonstrate the knowledge and need for sustainable development. + Life-long learning: Engage in independent and life-long leaming activities in the context of technological changes in the Computer engineering field and allied industry, I], Competency and Practical Skills Develop general purpose programming using Python to solve problem ‘The practical is expected to develop the following skills: © Write a Python Program using ‘while’ loop © Write a Python Program using ‘for’ loop ‘© Develop a Python Program using Nested loop IV. Relevant Course Outcome(s) Develop Python program to demonstrate use of Operators Practical Outcomes(PrOs) Write Python program to demonstrate use of looping statements © ‘while’ loop © ‘for’ loop Nested loops VL. Relevant Affective Dos 1. Follow safety practices 2. Demonstrate working as a leader / a team member 3. Follow ethical practices n related Outcome(s) Maharashtra State Board of Technical Education| a Scanned with CamScanner [=+! pe >peaug e==¢ th C1) 404vd % Dr asyn door AM tk Co typed (= POS 4 Ku) sod C4161) eSou ug £ voy 8 (1+ 5m00" 1) abo vs § YY GS = SMoU deop potson FF O€) tured 2 SFIMZ ure soy [. Fseed. ©, (Fd Udy (1 ROP TOE sadoul © Fuse y2,¢ ;, 000009, ajddo, J = SPAT Joop Oy HE =: 2p°D woubody | xeyuss sdzouos stn axensny o1 sojdurexe aaj smoys uoN2as Sutmojog ‘doy szqerm spisui doo] 240 26 01 Smojfe aSendue] SunmuresSaid uowpsg :sdoo] paysou (9 i289 poop Sten = yy tour GIST eoRKg in Bom Scanned with CamScanner wowed, sais) Sie sod | wowed 20d SV é Tue J) speuy | puEnd z Beng _——™s Adoausd ot oF z wosy ssoquinu sumtad OM huerragrout $ -psiaa a91a 30 dooy o]tys Bs = ojo Aue Jo apisut doo} Jo ads St Rao 880g eens 2 jddo sv si afenSue] SunmurerSosd uous ic = $d (90 oo -adaouos ot areaisnyqt 01 sajdurexa may smoys uodes Sumojjo4 doo} sotpour apisut doo} auo asn 0} smorfe adendur] Summuresdoud uopse zsdooy parsau (9 ~~ i949 poo odueus : ynuy yuo) ToTaeE) wT Hp Raw Scanned with CamScanner np enn. Jo poe 2 eHSEIEU. ls4n (se) puyad Ca 1) ebuov uy ve voy dowy soy Cusa (e 0 ph wo Dio ma (staussu 10j a2uds) lox sxuud ‘O1>x ay Ix 600} 104 0} doo} aytyss & Suisn wory apo uoYLsg SuLmo}jO} amp aBuEY TZ lax sewuud SX 2m ol-x (ausuiies poo voy Sumoyjoy ay wosy indino ay 2q pmo rYyA\ “1 02 patfimiap! fo mauaszypv ay) 24nsus oj suoysanb yams 240uL utsop ysmu s4ayav2.) a2ussafo4 sof suoysonb ayduvs maf 240 uos13 mopeg 2210N SUONSIND parE PWWIg — "NX ' wwuey kd wowdoaroq | € | —Fevopurm | wants Runeiadg |T a Ey ya padtuag) waIsss aaindwoy | 1 (hue yi) dF 2. eee | erseuon uomeaypods 440 au PPY) pasn sazun0szy “XT OEE) WOR Gar Baa Scanned with CamScanner VSFk } 2 3 2 2 3 2 2 2 a7 vl =- vu 5 \ r ze a yomyan. so pavorl aS SHEESH (= Pua.) yursd (ite o) abuvy uf Fo yoy coon bat BN Used (940) ahuow op 1 yoy (sonsue oj 20d) fet 1ous0 ‘swospuned v st WJM SYDON pu saqumnu e Sayer weMp weITOId UOMAYT aA °g squint Bur Sudip Jo wns ay spuyy pue soqunu eur Sayer usToId UOWLAY v OIA L JOAQUIN UANID B asIaAay O1 LMIOg HONKY AUN “9. saquunu v Jo jeuorary areinajes 01 uresBord uoyLKYe AIUA\ °s sau9s ooeuogiy tuud oF wiesToId WOUNKYE aM °F doo} 10 Suisn suoquinu jeameu 91 ISiyj Jo wns amp puy O1 uMEXTOrd HONKY EIU “¢ doo} 9]1ys Burs QQ] oF | uaanuaq sioquiN UOAD [fe YUL OF wrEsTOId UoIpAG B LAY “TZ 1 lol lolor lolo1ol > * ee eeene vee 4 ae a doo} Bu Humwvoyoy ou Wd “L siamsue soy o9eds yucyq 959) ‘ony nduy puoaaffip asm spuoprys fo dost K4o0o sous aansua ssn Synov_y :2H0N peg 1X TOTS) wo EN RaraaERETONT Scanned with CamScanner wouranpd SAA L JO PAUL maa eS aug eae | +umu = umu t. (wre) qusvd 957% Und Bh eo. = %wnu 9 Ce G01 =| woyg SVPGUMN YIAZ,) tULed ( =wou t QO tered tev (wag (+usU PY) feyed 81 2 =5wnu FL 3 ase toa (rare Cw = PU! Oy) Hyd 2 ey usy (+u2U Q=v (rucv Ce Pe BD fuse pew Baan Scanned with CamScanner uonwonpal (eoRID9, Jo PALOEL AVIS CAUSTIC a uvyp, avaw an[vV~r vafvs) 4d 6 ase qe vs Wap peru = 4 qe (war pee) uyed 2 ey = yw Weaf~pPeaV asym CQreva © 4, —O Wous S2surF 1922404 3 w) FLY Cay tused (0) 4d 314 xow Fh q+0 = wurp-e peau 12g o=9 ((,.20PA vou vot¥9n) foduy) fuy= ow (h (amoey = Omg 7 poled $=+ omg S Cuts) abuoe ul 4 v% (01 % | Worf Suaqamu 49 4MG,) fulyd Q = ams ( = wnu (e Scanned with CamScanner (it 7s nin Genial niamno ale oan Aas A | [cb vaqum~y Pesuemarl € tl vaq won pouthw vaqunu 0 JdIfVZ ETL Sood Scanned with CamScanner (rou! vaqunpy Pesan ry {ud Chee + Ol % Hau) FUL = Nad (or / %@ wy) tut = wou (or «1, wnuy uy = fEbrP go =f wny 2ym fama, BGGMN (Puberty? os Aad ([,29ned Oy eaqunu o sofV7,) PU!) +UL= WOU 9 (4203) ¢ulyd [-wnu = wu UM %# 474 = povy Z1sgamu apyym Camo © 42 P41 MY) toyed l= fou (TuPivpro4 puss Of vaqumn vopauprduyger= Uru [S eee yey Lagann _aweupelt” p—grqunne P2709 td | ; sag) hd - Rae oT (ree ' ciucen c eray) Ye © Csr © = wav pwny) tvs \ 2 wa) tS = — = 7 oO =? wn ayer | Scanned with CamScanner Try fun 92 4M — way = jwng __—__—— 7 Oo = haw (ums! | = ams .) ¢uyd (Flips ony we = ans “(ar | nv) fey = WnU (1 ‘fe lwnv) fur 24 Cp 8 8 = tre ayy equine peusiva.) yur QO eames ((.viqueny ° “dO 09.) duly pup Seong Programming with Python (22616) Bown SaNtnpet ever Number jo Find Factortal ") PINt CO Pacdortal of", awn j while own>=1 ¢ Fact = Fact & num Own = Num -} print (Rac) 6] num =int input ("Enter a number to reverse” )) prey =O PHO Criginal umber", num ) while numj=o3s alight = num = jnt Cnum “le 10 ) reve jot (num % | 10) int (rev *& 10 + liyit) print(" Reversed lumber '' rev ) ofp 3 Enter a number to reverse 123 original Waumber Reversed um ber 321 _ PRiAt © Wor paunur ven WN ee wi : (cata Scanned with CamScanner acne! ome Fy { dum = Intlinpat ("Enher a Number") ) vam = O print COriginal lumber " , cum) while num }=o8 digit = int (aum Fe 10) num = tat (num 110) sum = jnat (sum + digit ) print ("Sum = " ,sun) 3 3 ae le a Number”) ) reve 0 num) =nurm print VOriginal Clumber", 2un ) while num }=o0 § -ligid = tat Coum sh io) aum = fant (num ]10) rey = int (neve 10% ligt?) { print (" Reversed umber '', rev ) Tho numjps es reve \ petat (“Palindrome Nurber" ) | ees | print (" Not pallndrome Number") Scanned with CamScanner Scanned with CamScanner P, ractical No. 6: Write Python program to perform following operations on Lists: Create list, Access list, Update list (Add item, Remove item), Delete list y as aa —~_TRReyram Code 3 eae 3 indices. This 4 ms on list it ad AFGreate fist =“ i a= C’Apple” “Banana” , “Cherny” ] 3 print C'Crecdd List is, a) ‘es and basic ~ e@ - specific 3 ltt Access List ces to use the + a= [22,3), 28, 44,8, 50] sols with an ~5_| eprint CQ l2)) ional ethics, “3 af Computer ~5_|# Updete Joist tivities in the 7 ars Le] Id and allied : a- lst, extend(ts,6.4)) 3 print Cadet ) -5 7 coess, delete 2 ay Delete List “2? 1201,2,3,4,5] md print (1) 3 L- remove (2) se list, Access 2 priot (4) -3 — lop + > L'Apple’ s ‘Banana! , cherry "J —~4 23 stis ordered a 12,3)4, 5,64 ma 4 (3, 3,4, 5) <5 > oe 4 Scanned with CamScanner with Python (22616) Practical No. 6: Write Python program to perform following operations on IL ML. vi. vu. Lists: Create list, Access list, Update list (Add item, Remove item), Delete list , Practical Significance A list can be defined as a collection of vah ues or items of different types. The items in i lis are separated with the comma (,) and enclosed with the square brackets [] elements or items in a list can be accessed by their positions i.e. indices. This practical will make student acquainted with use of list and operations on list in Python. Relevant Program Outcomes (POs) © Basic knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to solve the broad-based Computer engineering problem. Discipline knowledge: Apply Computer engineering discipline - specific knowledge to solve core computer engineering related problems Experiments and practice: Plan to perform experiments and practices to use the results to solve broad-based Computer engineering problems. © Engincering tools: Apply relevant Computer technologies and tools with an understanding of the limitations. * Ethics: Apply ethical principles for commitment to professional ethics, responsibilities and noms of the practice also in the field of Computer engineering, © Life-long learning: Engage in independent and life-long learning activities in the context of technological changes in the Computer engineering field and allied industry. ‘Competency and Practical Skills Develop general purpose programming using Python to solve problem The practical is expected to develop the following skills: «Waite a program using List and performs operations like ereate, access, delete statements Relevant Course Outcome(s) Perform operations on data structures in Python Practical Outcome(PrOs) Develop Python program to pe! list Update list (Add item, Remove item form following operations on Lists: Create list, Access ) and Delete list Relevant Affective Domain related Outcome(s) " Follow safety practices z Demonstrate working as a leader / a team member. 3. Follow ethical practices Minimum Theoretical Background «A list is a collection which .s ordered and changeable. is , . ‘list s a collection of items or elements; the sequence of data in a list is 0 dered. — Scanned with CamScanner Programming with Python 22616) >>> list]+[40,$0,60] [10, 20, 30, 40, 50, 60) ‘The * operator repeats a list for the given number of times. >>> list? ['A 'B'] >>> list *2 TA, BY'A’, BY] iv) We can insert one item at a desired location by using the method insert() >>> list] [10, 20} >>> list] .insert(1,30) >>> list] [10, 30, 20) 4d) Deleting List: To remove a list element, you can use either the del statement if you ie exactly which element(s) you are deleting or the remove() method if you do not ow. i) Del Operator: We can delete one or more items from a list using the keyword del. It can even delete the list entirely. But it does not store the value for further use. Example: >>> list=[10,20,30,40,50] >>> del list[2] >>> list [10, 20, 40, 50] ii) Remove Operator: We use the remove operator if we know the item that we want to remove or delete from the list (but not the index) Example: >>> list=[10,20,30,40,50] >>> list.remove(30) >>> list [10, 20, 40, 50] VIII. Resources required Ix. Maharashira State Boa Sr. Name of Specification ‘Quantity | Remarks No. Resource (itary 1. | Computer System | Computer (13-i5 Ts per Batch | For ALL preferable RAM>2GB) _| Size Experiments Z| Operating System | Windows/Linux. 3. | Development Pyhton IDE | Software Resources used (Additional) : Sr. Name of Specification a No. Resource ° T. | Computer System _|° rp c1b ene 2 | Operating System _| Win dows \ 3, | Development Python 0 E Software 7 sd of Technical Education Scanned with CamScanner Programming with Python (22616) X. Practical related Questions Note: Below given are few sample questions for reference. Teachers must design more such questions to ensure the achievement of identified CO. ‘When to used list Describe various list functions. Write syntax for a method to sort a list Write syntax for a method to count occurrences of a list item in Python How to concatenate list Justify the statement “Lists are mutable” Describe the use pop operator in list AURYNNE (Space for answers) AASLALPS.. Boe : . arbists are used. to. store mulit ple a Sige Vario Ble an a4 “append C). 8 Adds an elemen} at the e of the List. Bi] clear C)f Removes all the elements st. si Tose CS dds “an aloneay “ak he position =~ ix] po P cj 8 Removes “the ‘elemnend od ihe Specified position . ~ ~ fb Syrloee Eel seed hee oesense “BOF coneed Celemen) J, Uisl2 car be. concatena) ed by using eadend cy methed or Cr) operalo Sha Lists are Mmulable means you con cha conten i ane. thet wt. GS thon Bist" pop CY isan’ tabuGif Fane lion FH Python thet removes “and relurns the last value From jhe bist en the ‘given index Va without changing. their 3 Scanned with CamScanner oo XL Exercise Note: Faculty must ensure that every group of students use different input value. (Use blank space for answers or attach more Pages if needed) 1. Write a Python program to sum all the items in a list. 2. Write a Python program to multiplies all the items in a list 3. Write a Python program to get the largest number from a list 4 -Write.a Pvthon_program.to.vet the from.adlich.. a] a =(81,52,93,64,35] pcint (Original List i$", a) a-sortl) : erint (“Smallest umber is" , afo)) ) : s|_a=[8!, 92,93, 64,35] . print C' Original List is" , a) > a-reverse C ) Sumy 3 prink C' Reversed bist wy", a) > |g azf2,.9.4 9 > b=13,5,4,9) 2 def common (1841, 1542) $ 5 relurn Jist (sebUstl) & set (st2) ) ary 2 e=common (a,b ) - -3 point (e) = a 2a artan, kt, 58,22, 31, 49,8, 23) iia C Orta ist 3s", a) - J) 34 for i in _ponye (0. den lay) % ee 9 ott “Te2 oT a 3 ort C0 a) 2 Scanned with CamScanner Programming with Python ( 0 NL Exercise a Note: Faculty MmUSt ensure that (Use blank space for Write a Python program t Write a Python Program ti prio} Comginal cassort lt). print ("Jorge Foumber.| Scanned with CamScanner Programming with Python (22616) Practical No. 7: Write Python program to perform follo 8 Operations on Tuples: Create Tuple, Access Tuple, Update Tuple, Delete Tuple 1, _ Practical Significance Like list python supports new tuple as a distinct structure. Tuple are use to store sequence of python objects which are static in nature. A tuple is immutable which means it cannot be changed. Just like a list, a tuple contains a sequence of objects in order but once created a tuple, it cannot be changed anything about it, I. Relevant Program Outcomes (POs) + Basie knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to solve the broad-based Computer engineering problem * Discipline knowledge: Apply Computer engineering discipline - specific knowledge to solve core computer engineering related problems «Experiments and practice: Plan to perform experiments and practices to use the results to solve broad-based Computer engineering problems. * Engineering tools: Apply relevant Computer technologies and tools with an understanding of the limitations, « Life-long learning: Engage in independent and life-long learning activities in the context of technological changes in the Computer engineering field and allied industry. III. Competency and Practical Skills Develop general purpose programming using Python to solve problem. ‘The practical is expected to develop the following skills: Write a Python Program using tuple IV, Relevant Course Outeome(s) Perform operations on data structures in Python, V. Practical Outcome(PrOs) Write Python program to perform following operations on Tuples: 1. Create Tuple 2. Access Tuple 3. Update Tuple 4, Delete Tuple Vi. Relevant Affective Domain related Outcomes 1, Follow safety practices 2, Demonstrate working as a leader / a team member. 3. Follow ethical practices VII. Minimum Theoretical Background A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. a) Creating a Tuple: Creating a tuple is as simple as putting different comma- separated values. Optionally you put these comma-separated values between parentheses also. ‘Maharashira State Board of Technical Education a Scanned with CamScanner

You might also like