0% found this document useful (0 votes)
35 views

Python Practical

Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
35 views

Python Practical

Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
2110123, 5:46 PIM Untitled ipynb -Colaboratory Drint(‘lopging in to education!) else: print(*please type the URL agzin.") print(*print you are ready t0 B01") ile “claythonctngut-23-cadeeseen7aBs", Line 4 ‘lee syneaxerrors invalie syntax ‘CORRECTION OF ABOVE ite = Se print (Logging 40 to eduCaTZON!") print‘Plesse type the URL again.") Drine('You are ready t0 gol") Ce oeeing 4 to educarzon! If statement if.elge statement In computer programmingiwe use if statement to run a block code only when a certain condition is met.There are 3 types off statements, WRITE A PROGRAM TO CHECK WHETHER THE GIVEN NUMBER |S ODD OR EVEN rancine(input (“Enter any munber")) HF county prine("the nunber 4s even") oh: Srine(*the provided nunber Ss o8d.") enter any nunber765 The provided nanber 1s od ransine(Anput ("Enter ary unter") SF (oun) eine(*The number {5 even.*) Deine(“The provided nunber ts oid Enter any nunbers32 WRITE A PROGRAM TO CHECK WHO IS THE YOUNGEST AND THE OLDEST ‘from are.constants Seport AT_LOC SON. OONDARY Sint(ingut (Center flrst person's ag@")) ‘Cinput(Tenter second person's age")) cint(Snput(“enter third person's age")) FF (232) and (0) prine("a 1s eleest and c ts youngest") elit (ba) and (39 prine(*b is oldest and c ts youngest") e1i€ (90) and (3) print(e tr olaest and s ts youngest") Brine("e ts youngest”) ntps:ifeolab rosearch google. comlrivatthrkl1SusxamNqe4CNpJV3SERBB3NmitscrolTo=BoWaStqkQBLX8un qier=A&printMode=tus 10 2110123, 5:46 PIM Untitled ipynb -Colaboratory enter first person's ages? lente third person's agese WRITE A PROGRAM TO CHECK IF I'S LEAP YEAR OR NOT? Ifa year is divisible by 4,it is a leap year,but if it is a centenary year like 1900,2100,etc,it should be divisible by 400 to be a leap year. TF tyeartaee) = 6: esp year") 1 (yeartiee) == @ prine("Leap year") eli(gyean #4) = 8 print ("leap year") Print (Not Leap year") Control structures Loops and decisions ifforwhlle loops itis not necessary to put else inl. While is condition-contrlled loop For is count count contlled loop nested loop loop insie anther loop using 2 for loopyurite 2 progran that ne decinal equivalents of 1/2,2/3,2/4,1/38 ‘inttalizing 9 variable with 3 for a in range(2,13) ‘petting 2 (here p) diviged by the current runter and formatting st prarece”(e}C@)?"B/8) aa 0s 37s elpasssaasssaa353 aya: 02 asi 02 2/6: 0. 26sccosscooests yt: alaanesruazesriaaes 4/9: @.nuanasatiman ane ot ‘tieite 2 progran for loops that loops over a sequence.what 3s sequence? olor liste['ree", ‘green’, “white, pink’, “purple, maroon] -ntps:ifeolab rosearch google. com/riva thnk 1SuxamNqo4CNpJV38ERBB3Ne#scrol To=BoWaSIgkQBLXAun qior=48orntMode: 210 2110123, 5:46 PIM Untitled ipynb -Colaboratory Hor loops tn étetionary eradeeeas'g's2: 0 3!" for Sin fr shee print i) on ‘sun of all the List eenents Nam [2,2, 31454647 88,18] pesne(Sum) 6 ‘tteite 2 progran to print the runters fron one to five using the while Toop forint. (Counts, count) print the value of count ‘ount-caunted| acrenant the value of count by 1 ‘indentation 4s Soportant for wile loop to avoid errors ‘tecite 2 progran 246 20 consecutive nunbers starting fron 1 using while loop prine(*the sun of frst 20 nunberse*, sm) Uf print 4s outside indentation ,only final output will print mangas gamer RECs emer: Regie gaer Racie geet REDE REES ‘tieite a progran using while loop thet aske the user for a number and print = countdown fron that nuber to zero. eovol. (input (“enter the nomber=")) Print("he counteoun fron” ne) ntps:ifeolab rosearch google. comlrivat thnk ASusxamNqo4CNpJV3SERBB3NmiscrolTo=BoWaSlqkQBLX&unigior=A&printMode=tus ato 2110123, 5:46 PIM Untitled ipynb -Colaboratory prin(count) t) ya scout): stricinput(*enter Firat steinges\e") stravinput("enter second string::\n") boctean-nesrly cova (srt, str2) s¥(boelean): Prine(Steings are neariy equal.”) print Steings are not equal.") Enter second strine Strings are nearly equal ‘uyirsxe 2 function dupe to Find a1 aiplscates in the List. et cups(unlist) fuphicateset) for ele in ramlset aruplist count (ele) ito=2) duplicates(ele]=c print("Duplicate elavents are:\n" duplicates) ramiset-() eint(input ("enter runer of elements £0 be insert:\n")) for tin rangs(e} elesint (input ("Enter etenent")) runlist.append(eie) sups(nnist) Enter nunber of elanents to be sneer: Enter otenent2 Enter elevent Duplicate elenents are: (2s 2 3:2) ‘aesunize 5 function ball collides that takes two balls as paraneters and conputes if they are ‘tecolL ising, Your function should return a Goolean representing whether or not the balls are Sngort ath ser ball collide(bais_tupiet,al2_tupie2) dnnaih. sqrt (ball tuplet(2)-ball tuple2(@))**2 + (eatl_soplet(} batt tuple2t})""2) ¥(Ge>(oat1_tuplei{2}sball_tuplez{2)): bald tuptete(-2,-2,3) ani-taple2-(1,4,3) collisioneball"collide(ball_tuplet,ball_tuple2) (collision) Drint("talls are eollise.") print("Balls are not collide.") alls are collide, ntps:ifeolab rosearch google. comlrivatthrkl1SusxamNqe4CNpJV3SERBB3NmitscrolTo=BoWaStqkQBLX8un qier=A&printMode=tus eno 2110728, 546 Pat LUntiled0.pynb - Colaboratory 7186 completed at 457M ex hitpsieola research, google. comidrvel1-rk-ISuxamNNge4CNpJV3SFRBE3NmiscrolTo=GoWaSlkQBLX&Lnigior=4&priniMod 1010

You might also like