0% fanden dieses Dokument nützlich (0 Abstimmungen)
48 Ansichten16 Seiten

Python Swostik

td6

Hochgeladen von

saswatpattanaik62
Copyright
© © All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als PDF herunterladen oder online auf Scribd lesen
0% fanden dieses Dokument nützlich (0 Abstimmungen)
48 Ansichten16 Seiten

Python Swostik

td6

Hochgeladen von

saswatpattanaik62
Copyright
© © All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als PDF herunterladen oder online auf Scribd lesen
Department of Computer Seience & Engineering Faculty of Engineering § ‘Technatogy (TEND A\ss-1GNMItnt at 7 ables? 1. Which of the following statements is true about Python ¥ a, Variable names can start with a number. b. Variables must be dectared with their data types. ¢. Python variables do not need to be declared before use, 4. Variable names can contain spaces. nie in Python’? ble | 2. Asa follow-up of Q. 1., which of the following is a correct variable n a, Ivariable », variable. . variable-1 d. 3. Mention 2 ways by which you can apply comments in Python. ne difference between the input()" function and the ‘print()" function in Python? 4, Whi ton integer in Python? 5. How do you convert the string “123° ¢. in("123") d. float("123") a str("123") b. int(123) 6. Differentiate between the following operator a. sand == b. /and % ©. fand If there is no difference, then mention why, and if there d. * and ** is a difference, then justify with examples. 7. What is the output of the following Python code? a=int(input("Enter a:")) b=10 print(atb) 8. What is the output of the following Python code? print(c, "Batman") 9. How do you prin the exact following lines in the exact order using only I prin statement in Python? Hit We are studying "Python". \n I hope you all are doing well. We are going to have a great time! ig address. The address should be 10. Create a program that displays your name and complete mail ‘Your program does not need to printed in the format that is normally used in the area where you live. read any input from the user. 11. Given an expression P(z) = «3 + 2x? + 31 +4, try to find the value of P(2) pythonically. from the user. The program will continue by 12, Write a program that begins by reading a radius, r, with radius r. computing and displaying the area of a circle with radius rand the volume of a sphere Use the pi constant in the math module in your calculations. Hint: The area of a circle is computed using the formula area ‘The volume of a sphere is computed using the formula volume Name;————- Regd. Number:——-——-—— pepartment of Computer Science & Eng Fawatty of Engineering & Technology (ITER) \ ty from the user and then displays the sum of all of ied using the formula: that reads a positive integer, Vrite a ram f 13, Write a prorat ty The sum of te first n positive integers ean be compu 14, Evaluate the following expressions: ) and (€ =*, print “ok”, 16, Import relevant Python modules and print the values of ¢* and Otherwise print "ok anyway”. 17, Evaluate the following expressions involving arithmetic operators: 2, -7°2048/16*2454 b. 78#2/9%3 . (7-4*2)*10-25°8/5, 4. 5% 10+10-25*8//5 18, Evaluate the following expressions involving relational and logical operators: ‘a. ‘hi’ > "hello’ and 'bye’ < "Bye" b. ‘hi’ > “hello’ or "bye’ < "Bye” ¢.7>8or5 <6and ‘lam fine > "I am not fine’ 4. 10 !=9 and 29 >= 29 €, 10 !=9 and 29 >= 29 and ‘hi’ > "hello or "bye" < "Bye’ and 7 <=2.5 £.5% 10+ 10 < 50 and 29 >= 29 £.79*2<=5119 %3 or bye’ < "Bye" h.5% 10 < Band -25>1*8//5 72445 >80r5 j. 7/4 <6 and "1am fine > "Iam not fine’ k, 1046 #22 !=9/4-3 and 29 >= 2919 I. *hello’ * 5 > *hello’ or *bye’ < "Bye" 19, The program that you create for this exercise will begin by reading the cost of a meal ordered at @ restaurant from the user, Then your program will compute the tax and tip forthe meal. Use your local tax rate when computing the amount of tax owing. Compute the tip as 18 percent of the meal amount pe 7 oe ua fom your program should include the tax amount, the tip amount, and ee aie ican ie tax and the tip. Format the output so that all of the ) 20. Create a program that reads two integers, a and b, from the user. Your program should compute and 7 Regd. Namber— * Department of Computer Science & Engineering Faculty of Engineering & Technology (I * The sum of aand b * The difference when b is subtracted from a * The product of a and b \ * The quotient when a is divi * The remainder when a is di * The result of logi0 a * The result of ab Hint; You will probably find the log10 function in the math module helpful for computing the second last item in the list, 21. Write a program that determines how quickly an object is travelling when it hits the ground. The user Will enter the height from which the object is dropped in meters (m). Because the object is dropped its initial speed is 0 m/s. Assume that the acceleration due to gravity is 9.8m/s?, You can use the formula vy=/(v7 + 2ad) to compute the final speed, vy, when the initial speed, 0, acceleration, a, and distance, d, are known. 22. Write a program that begins by reading a temperature from the user in degrees Celsius. Then your Program should display the equivalent temperature in degrees Fahrenheit and degrees Kelvin. ‘The calculations needed to convert between different units of temperature can be found on the Internet, 23. Write a program that reads a four-digit integer from the user and displays the sum of its digits. For ‘example, if the user enters 3141 then your program should display 3+ 1 +4 +1 =9. 24. Write a program that reads three integers from the user and displays them in sorted order (from smallest to largest). Use the min and max functions to find the smallest and largest values. The middle value can be found by computing the sum of all three values, and then subtracting the minimum value and the maximum value. 25. Create a program that reads duration from the user as a number of days, hours, minutes, and seconds, ‘Compute and display the total number of seconds represented by this duration. Name; Regd. Number: Department of Computer Sch i Petey ot Engineering & Technology (TEN) Ansuiess:= : =) 4) &: pytton variables do not need to be cleared before use- Expienatio Rythen fe een yet ee mmeant wou, deny need to oS we the tate are of a Variable before of of avanable esVdetermined at the 4éme. usi 7.3 barra on ‘he volue rd to: a) voviabiet Ub) | 3) Two J 40 apply” comments 2 fyhen b *< SPN Riss ao sine comment id") le ine comments + pet ("Hallo + hy) Mattl-Line comments ¢ cnaeosm) TWF fc a multé-tine comment You con Drite enutépie ifnes here + up print ¢ “ Hello a ") 4) fap; Reads input from the user: Tt prompts the user to antey 4 value ond returs the nput at a sting 1 Used for user tnterattion: 44 (/J often used te act tafennation from dhe user , uset such as thely name sage or preferences. Name:—--———--—_—__ z Regd. Number; — ——— Pr Zz seco see — @xample codes Department of Computer Science & Engineering Faculty of Engineering & Technology (ITER) ames input" fore se fame: "): Print C" Hello, * + names “1") Enter four name: Alice Hello, Alece! priatea: a ts and prints ieplays output on the console: Ht takes one or move aque P they 40 the console 7 7 ', zd 40 shed -the . snformation: TV's commonly/ Us + seq for asp én 2a vesuits of canbe 5 mest sor other data example codes yesult = 5+3 parc’ Te result 352" vesutt) Outpus:- The result és: 8 5) fat (11231) fry) Operator) = 6) ca) (=) CAsttgeement Operator) vs ) Cequal peas) += (Asséqnment) = Osea +. rai a value +? Ua variable. ¢ the value 5 to variable %- m=5 wee coat Used to cheek FF two values are equal. en Vas priate % “Difference : > 45) 4 Truer cheeks V4 x le equal 405. mane © value rwhéjel==) cheeks for vey Name:-—— — Regd. Number: Department of Computer Science & Engineering Faculty of Engineering & Technology (ITER) (Modulus Operato ions ond vehuns the ynlient ay g (b) 7 (division Operator) vs > (/) twiviscon): Performs di ttoating/peint number » eg. result 1013 g prot Cresult) trourpus + 3-3333 > "le (Modulus) + Retums the remainder of the division Wy verpainder = 10%. print Cremainder) spoutputs 4 (since 10 divided ayia 0. remainder ef 4) Difference : (/)vetums the quotient pwhile Ye returns the eermaindey (IC Pivisiony ve IC Floor Divison): 7 I boivision) Pestorms yeqular division and returns the reswt ae q Ftoasing. point no. vesult = 10/3 print crecuit) goupur! 33333 DW CFeor pivision) sferforms division and wrdums the largest integer ‘that is less than or equal t the -quotient U J ea yeutust = 102 print Crecutt) Housput?3 CHoored veer oP divisisn) Difference: (1) returns & ttoating- point reruit ,whiie I Tekans the Poor of the nee reg) (A) (A) Muttiplication vs cme) Ctxponentiation): > % CHultipicatitn): Yuttplies 100 numbers, 9 ew 1 583 pilot Crem) FP Oudpur ss: > ** [ Emporentiaton): Relies the fect o umber 10 F the second no- the power Namo:——__—___— Regd. Number; & Engines Department of Computer Sciences Faculty of Engineering & Technology (ITER) result = SHS provevecult) #F ouput: 12s ¢ since 543-125) Ditterence :(4) multiples numbers + while (aa) raiser a a0: 48 the paver of another: J(2) a+ tat Cimputc "eoter a: ")) de User fapurs a volue as 20 Hoverwsiter the value ef a with 20 b eto ae Astigns 10 tb Pint Cath) 3 Prints the sum of a and b 7 (g) as "nana" # Strim ‘nana ‘(with a space) ® tt Inkder & crath The 7) printé ¢) “ Batman) Prints the Yeprated “ foad C inpurt "Enter ‘the resius")) area + matty pi vodius R82 volumes ( 4/3),* math: pi 2 vadiue at 3 print ( # Area of the drde\" area) Regd. Number:— © Department of Computer Science & Engineering Faculty of Engineering & Technology (ITER) print envotume of the «phere 1", volurne) output: “Enter the radius: S Area of the civele 1 78-5296163397 4403 Vowsme oP the sphere: 523-588 775598 2984 fot Cenpure "Enter a positive meen game (ne Cn43)) NR ative ney ics, eusn) uae print ¢ tt The sum of the first ow put Enter a potitive i Re sum of the “first 10 posive eye ie:55 (4) (a) arto rbs5 t=O tach’ = ocs’ > Fake’ to=25'% 'Faise’ t not ¢ False)” oy "True! yer 10 4 ve ge tmet Cezeb)’ > Ae eee > to (True! + (nore essb) ana ceca)" ‘True and True! op Thue! tPalse or True’ = ‘Trac! 5: $b Macb)or Cnet Cestb) ond ce 50, final onmwey for aya sta: b7S)cr0 2 Tue. Regd. Number: Name:) ———— tof Computer Science & End ‘coring & Technology ( Department Faculty of Engin Uy ae bare beer! @2taa 4. Sack! tay chao! 7 tFalse Qe teeth’ sy PNR tnoye Fats)! CTr8C ‘False? tque and False’ sp (False? 2a))' - False oF False’ > ‘False a ‘notcestb)' > 4. teea’ ey apaacnal’ 5. tEnore c=zb) and ¢¢xa))” *P and C(t G+ Mach) or Cnor Ce=#b) $0) he final anewer is False (Is) Coder: prieipal=tooo onnual-vate = 0-12 amount — (9: prindpal » C14 onnual-rvate ) ** 10 amount-20= principal # 1+ annua). vate) #* 20 amount -30 = principal ACL? anhual- rate) RF 30 prnre ¢" Apter To yeors 1 Rs. Fameuntd-10!-ah3”) prior CF pdier w tors Rs. Gamount-20: af ¥”) pent Cf" Apter SS Rs {amount 29 :aP3") Qusput After 10 years: RS. 3105-85 After 22 years: Rs 9604-09 After A RE 24241.24 Department of Compute (wy eee atede import rath e-pés mathse # math:pi pice: math:pra mash-€ printe se # ple” epi) pric "pices pire) Tt e-pi> pi-e: peat cok") reve ape Ousput etpi -$39734 22649566 eke pide: 553473 42924 73566 OK wg a (a) ~ 820 4 8/ lot QtS4 Lg gn0 “140 genie roSPRS ord +54 =~ 85 ) p gata dhe qanar 44 4aacs 3378 Science & Engineering Engineering & Technology (ITER) (O CF-AAZ)K L0-2SA BIS 4 yA 48 -dt10 2-10 agra 20 2005240 10-407 -S0 (a gmat to ~2SK EHS Sn 1075 Ettoris asa = 200 2001S = +0 Is-402 - 25 Name:———— - Regd. Number: — Department of Computer Science & En Faculty of Engineering & Technolo (0) false Cb) True CO false () Tue (e) Tue (2) True yp False Wh) False UD) Wee (p> Fatse (iy Tue (1) Tue meal-cost = Heart input ("Enter jhe cost of the meal :")) tax rate = 010 Aan amount = meof.-costX tan-THre ep - amount = meal cott * 018 total cost = meal-coct +4ax-amount + Hip-amount print C* Tax amount: “Ve 02# “4, 40x-arnoun ) prerc’ Tip amount: “/. +24" So tip- amount) prinrc" Total cost : "Tee" fe tated cast ) Oudput Enter the cost of the meal : 100 Tax arround: 10°00 tip arnoum: 18-00 Torod cost 1128-00 Name:——————_____ Regd. Number:—— Department of Computer Science & Engineering . Faculty of Engineering & technology (ITER) ‘ 20), tempor math a: Tot Cinput C" Enter the first tote be int Gaput¢ "Enter the second sum: ath ditterence > a-b produtt sob quotient: lb remainders a%b Jogio- a= rasnepoen) pear a print corsum:", sum) prac" pi tterence :" ditferen ce) *y produit) print cnauotients") qpotent) proare" Remainder ¥ vemaindet) rege) wee ” prac * be", power) print ( “Product Enter the firct “oT 40 “ge 5 Enter the second sum 315 differences S product 150 Quotient? 2 Remainder teqiocad 0 arb : 100000 Name: ———-——— Regd. Number:— a 4 oava— ineering Department of Computer Science & Engineering Faculty of Engineering & Technology (I height = Stoat (input ("Enter the rep fo. meters + » intial speed =0 Otteteration = q.g 7 Tenal- speed = math. sqrt Coitial- speed *# 2 4 2# atteleration # oy Print ¢** Final speeds”, nal speed mis") pa Enter the height en metere :10 Final speed: 14 :00314.2839047327 m)s Celtis = float (input ¢" Ener the temperature in Celsiues ")) Fonrenheit (4/6) ® celsius +32 kavio = celgfur 4233 15 prot" Temperature in “Fahrenhds 3” , Aebeeheit , sees) paar ¢ Temperature in Retvin 27, kavin , °K") Enter the Aemperature in Etsius : a5 Temperature in Fahrenheit: 79-0 °F Temperature in Kelvin: 298.15 x Name:-—————-—— Department of Computer Faculty of Engineering & T \ce & Engineering hnology (ITER) number: {ot Cinpul ("Enter a er ey thoutand = number I 1000 hundwed = (number % 1000) /1100 fens (number Yo too) 1/10 oni > number Yo 10 sum. of digcis = thoutand + hundered + 1en4 unt Pre sum oF ay 2", sumoF ay ) Output Enter a four-digct “ge 4 1234 Sum oF oe to GY cones: == eee umd = tnt Cfnput C" Enter the Fired ioteger int UEnpur "Enter the second num3 ink Eenpurc “Enter the third for $maltect: mia numd, rumay pum3) eget 2 Maxt eumd, nung, num3) middie = num4 + numa+ pum3 + - smalles} - Ga phar C" Sorted order: ") smallect , middie, we al Enter the first énte Enter the second meyers s Enter the third tengo? 8 Name: Regd. Number: — ———— & Engineering Department of Computer Science (ITER) Faculty of Engineering & Technology Sorted order: 5 & 10 (as) = tode:- days = ent Cinput ("Enter the number oF q hour = fnt ¢ Snput¢ epi elnuebe of .»)) ménutess tot Cinpus ( “Enter the number of ménuters”)) “Enter the number oF seconds :"")) Seconds = iat Cinpur¢ 60460) ¢+ (minutes #60) 4 total - seconds = fe A440" G0) t Chourt® seconds ana “Total seconds: ", toral- seconds) aap Enter the number of days : 3 Enier the numba of hows: 3 Trier the nuspber of ménutes: 4 friw the nurther oF seconds! S

Das könnte Ihnen auch gefallen