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

Lab Manual

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

Lab Manual

Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 54
WPF LEVEL ALE EADZLDOOCA*APAGAGAADAASAEUV PRACTICAL-L Description: ‘Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals or characters in these variables. Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically values to variables. The operand to the when you assign a value to a variable. The equal sign (=) is used to assi ight of the = operator is the value stored left of the = operator is the name of the variable and the operand to the in the variable Create a program that asks the user to enter their name and their age. Print out a message addresses to them that tells them the year that they will turn 100 years old Code: Name = put Cente your merme = age > intCinput C’ Hew old you anec- “) CYeas = 2022 ageloo = Ciee— ege) + C_ Yeah agetoo 2 CC year - age) t (oe Priv CHorne ,” Will Tusm [co at year cyeloo) 12 ourPuT: Cte, your mame : Boss How old you ane - 52 Bess Wil) dum leo at year Zeto Post Pra Questions: 1, Which one of the following is correet way of declaring and initializing a variable, x with value S? (a) ims (opin x=5 (dpdectare x°5 2. All keyword in python aren (a) Lowercase (1) Uppercase ne of the tk 3. Which of the following cannot be a variable? | (a) _ init «yin 4. Which of the following characteris used to give single-line comments in Python? | @ (by! oa © the following code snippet? ‘5, What will be the o print(eype(S /2)) | 51/2) cavrieaeanirian () int and float (©) Mloat and float (4) int and int | Conclusion: Pit np sk oakhdatt bae bs Ob OO ae & ac! {Fo he statements ed ih wie pe che tent enc wh he ‘den cans ome ea es "he emmys ary dedi the gc in +a Art i. ‘ss sett feo ch mae a porrlbinytn.Asinge it my ‘com Daye epen Sig tw Osis ar ile hy en be ere ‘stayin ween anne inc The leita nel cing eine ‘ee the ning shih eg hefner ne at ete sn iat apg clones hela wh nce ning iso din place ‘Nt tin apne leh tin pt cosas eee ‘Ne Lots to peeing en i utr ein ne ment ‘chon List pend td ping ingen heel of he La Sine pi) + tem ot mo eae fhe at ABE7Z7TGOIIZBAAIBCHE AZZ AW FE PRACTICAL Deseription: List Comprehension List comprehension offers a shorter syntax when you want to create a new list based on the values of an existing list. Example: Based on a list of fruits, you want a new list, containing only the fruits with the letter "a" in the name. Without list comprehension you will have to write a for statement with « conditional test inside: ple: fruits = [*apple”, "banana’ ‘cherry, "kiwi, "man newlist = [] for x in fiuits: iP"a" in newlistappend(x) print(newlist) Output: ['apple’, banana’, ‘mango'] 11, 1,2, 3, 5,8, 13, 21, 34, Hb=[1 ins only the ele m:T 3,4, 5,6, 7, 8,9, 10, 11, 12, 13] and A vo list 1s that are common between the lists write a program that ret ts of different si Write this using (Without duplicates), Make sure your program works on two at least 4 comprehension, Self: Randomly generate (wo lists t0 tes Code: ‘a EU 4,27 3,5. ¢,13, 2134/55/11 se a eee ele @-CA Ooms inn cle Roienton| b 7 28 fos, Sin b: — | Wo fess: Pi mot im c: Gappend Cid w - o * ‘Pe ® Print CoD Output: o>, ste | Post Practical Questions: (1) What will be the output of the following Python code snippet? k= [print(i) for iin my_string if not in "aciou") (a) prints all the vowels in my_ string | (b) prints all the consonants in my_string | Corpses FFT as aps | (0) pri only on exceuting print(k) 29 iii nicc ace edbedeeneene Pee see esa TEE EL TITL Definition and Usage ‘The pow() finetion returns the value of x to the power of y (xy). Ifa third parameter is present, it returns x to the power of y, modulus z Syntax: pow(s, y, z) Aim: Let’s say I give you a list saved in a variable: ‘one line of Python that takes this list and makes H odd numbers from 110 power of 2 from 1 to 8 ns prime and n ange 1 to 50 on TH) 4,8, 16, 25, 36, 44 64,01 lool cote (ed EES CL ee ees Oo st.append Ct) Print (o> Output: [4 16, 36,64, lee] 35 pectoermamin fr n-ne tome ‘een of mer in he sme ent Te Fac sence spre a | Teseqemeeete the ict NARI SNaet Cleon * , tee eo Cibo n=) + fibacn-a9) 02 ick Cipuk Erhx Be rumba: ")) | Netacsal 2 | pk iat) Eee EEE ELE EERE RL DIOLLIPTd PD J { | route Questions 1 Miho lowing bo decreas? \ ara oa dae eve meh ater cars a fio efition *) Meningie able ant cero ert aces eta clas meses Faces vrs pag of rae os Aton imposes of pet sae esp nt sly oie | afbubiseet ato OSegetent tise | xa law ec ei i fa cl? | atid ae ect ‘esa ype nin les? 2) Demis te bj ne aye ete a nna ee —

You might also like