Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

Python Final

Python

Uploaded by

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

Python Final

Python

Uploaded by

dartionjp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 11
KADI SARVA VISHWAVIDHYALAYA B.E. Semester VI CC 605.3/11 608.3 ~ PYTHON PROGRAMMING Time 1030 AM to 6130 PM TOTAL MARKS: 70 Instructions Answer each section in separate answer sheet 2 Use of scientitie calculator is permitted. 3. All questions are Compulsory. 4 Indicate clearly. the options you attempt along with its respective a 5 Use the last pa ‘of main supplementary for rough work. SECTION 1A. Give the output of following code. 1. print-( { (a,b) for ain cange(3) for bin range(a) | ) 2 a={1,"element’ ] bral] a.append("v") b.append(’") a(2}.append("abe") print (a) print () 3. print(‘abbaxyexzxabb'.coust ‘abb', -10,-1}) 2 4 dictionary = Google’: 1/’Microsoft': 3) dictionary2 = {‘Microsoft': 2, Youtube’ : 3) dictionary1.update(dictionary2}; for key, values in dictionary1items(); printikey, values) et(("test',"exam’,"rem’, practical") geset(("allow',"test®,"eval’,"rem'}) print (p.symmetric_diference(a)) 18 Write a program to find the prime numbers in a specific range using filter. 5 OR Q-18 Write python program to find Armstrong number in a specific range using map. Q-2 Answer the following questions. A Write a Python function that takes two lists and returns True if they have at least one common member. B Describe python garbage collection mechanism, 5 oR @2.A Explain memory management of python using an example. 5 Page 1 of 3 o> 3A Q4a Write a python program to determine if @ sentence is a pangram or not. A pangram is a sentence using every letter of the alphabet at least once Answer the following questions Explain copy operation of list (with reference and without reference) Given a string 5, return a string where all occurences of its first char have been changed to, except do not change the first char itself. For example : google -gootle , Exam ~ Exam, bubble ~ bu**le oR \write python code to read a text file in python and do following: © print no. of lines ‘= print no. of statements © print no. of unique words Write python program to find total number of digits, total number of small alphabets and total number of capital alphabets from given string, SECTION ~11 Give the output of following code. X= "welcome to ldrp” print (x{8:2:-a)) print (x{-4::4)) f=(1,2,3) Ws(len (1)-3* 7) = (0) *3) print (I) pe impart functools Print (list filter (lambda x: x + 10,,range( 0, functools.reduce( lambda x,y: x *y, range(0.15})}) ) ) def increment_items(L, increment): ° while < lent} Ui] = Lf] + increment iste values = [1, 2,3) print (increment_items(values, 2}) print (values) 3,4, 5,31, (83, 6,1, 20) v= values(0}{0) for row in range(0,len(values)) for column in range(0, len{valuestrow])} itv < valuestrow}{column); v= values{row| {column} print(y) Page 20f3. 5 5 5 ae 48 asa Q6A Write a Python program to find the three elements that sum to zero from alist. of nreal numbers, oR Create user defined functions named Armstrong and Fibonacci in one file. Use the functions in other file by importing the file. ‘Answer the following questions. \rite python program to find whether the given number is perfect ot not. s Note: Perfect number, a positive integer that is equal to the sum of its proper divisors, Ex. 6: 14243 Create class python with following attributes 5 Instance variables x, y.2 ‘© Instance methods get_value, print_value ‘© Static method set_value Parameterized constructor, destructor oR Write a Python program to find the list of elements which has lowest 5. occurrence ina lst Input =[2, 2,3, 4, 5,5,5,5,5,5,6,2,3, 6) ‘Output: [2,4] Explain types of arguments using an example. 5 Keyword Arguments Positional Arguments Default Arguments Arbitary Arguments Answer the following questions. Define a class which has at least two methods: 5 getString: to get a string from console input validateString: validate string for following criteria 1. Length of the string must be between 6 to 12. 2. String is palindrome or not Explain string indexing and slicing using an example. 5 oR To create customize exception for checking string length, if string length is ‘more than 6 or less than 2 then customize exception must be thrown, Explain the below mentioned function using an example: 1) discard!) 4) reversed) 2) any) 5) removel) 3) isdisjoint) Page 303 Exam seat No: KADI SARVA VISHWAVIDHYALAYA. | GANDHINAGAR Semester_VI CE/TY Regular Examination May-2018 Subject Code:- CET 605-3 Subject Name:- Python Programming ‘Time:-10:30 a.m, to 1:30 pan. Marks:-.70 Instructions: ‘Answer each section in separate Answer sheet. All questions are Compulsory. Indicate clearly, the options you attempt along with its respective question number. ‘Use the last page of main supplementary of rough work. Section - I Q-1 Answer the following questions. .All compulsory) (A) How dictionary ean be ereat2d in python? Explain with example. 1) (B) WAP to Read a text file in python and do following: 6) [A print no, of lines B. print no, of statements C. print no. of unique words D. store cach word with its cocurence in dictionary (©) WAP Given alist, etur a st with the elements "shifted left by one (5) position” so (1, 2, 3] yields 12,3, 1] Example: 2,3) 3,1] 15,11, 9] + (11, 9,5) 17, 0,0} {0, 0,7) oR (©) WAPto Return the sum of tie numbers in the aray, returning 0 for an (3 ‘empty aray, Except the number 13 is very unlucky, s0it does not count and numbers that come immediately ater a 13 also do not count 0.2.2.) =6 tu (12,21, 13]=6 03,2,2,1, 13]=3 “a a4 a) @) Answer the following questions. (A) Write python program to remove duplicate values from list using user defined function, (B) Create class Idep with following attributes A. Class variable ent B. Instance variables x, y . Instance methods get_value, print_value 1D, Parameterized constructor, destructor OR (A) Explain string slicing using proper examples. (B) Explain Map() and Reduce() with examples Answer the following questions. (A) Explain the features of python. (B) What is Lambda Funetion? How can we use it? give example of it oR (A) _ Explain 5 different operations of SET( with proper example of each. (B) Explain S different operations of DICTIONARY() with proper example of cach ® Section — II Answer the following questions. (All compulsory) Give the output of following code AM=(1,2,34] pen |2.append(s) print 1,12 BA=[1,23] AE: (lea }-1 #2%(Teo( 1) +2) ] = [0] *3 print Give the output of following code 1. print filter(lambda x : x%2,range(-10,L1)) 2. pe set(("test","exam',"rem","practical"}) g=set({"allow", "test", "eval", "rem"}) print psymmetric_difference(a) 2s (5) 61 {5} (3) 13) (31 (31 (I 6] Explain the use of python in realtime applications. oR Explain the need of filter with an example. ‘Answer the following questions. (A) How to declare class and object in Python? (B) Explain module with suitable example. oR (A) _Explain the use of global variable using an example. (B) Give syntax and example of following set functions i. discardQ ii. clear() ii Issuperset() iv. intersection_update() v. difference() Answer the following questions. (A) _ Write python program to convert decimal number to binary using recursion, (B) Write a python program to print all prime mumbers in given interval oR (A) Write a python program to find factorial of number using recursion. (B) Write python program to print Fibonacci series using recursion, Bla i io} (5) (1 fo} 13 {5} (3) (3) (5 ee KADI SARVA VISHWAVIDHYALAYA B.E. Semester VI CE 605-3 / IT 605-3 - PYTHON PROGRAMMING “to-l eee ‘TOTAL MARKS: 70 Instructions: 1 Answer each section in separate answer sheet. 2. Use of scientific calculator is permitted. 3. All questions are Compulsory. 4 Indicate clearly, the options you attempt along with its respective question number. 5 Use the last page of main supplementary for rough work. SECTION -I QIA_ Give the output of following code. 10 1 M=[1,2,3,4] R= I2.append(5) print Il, 2 2 I=[1,2,3] If: (len( 1)-1 )#2*(1en( 1) +2)]= [10] #3 ] print | 3 print filter(lambda x : x%2, range(-10,11)) 4 print 10.0/4 5. p=set({"test","exam',"rem","practical"}) q-set({"allow", "test", "eval", "rem"]) print p.symmetric_difference(q) Q1B Explain custom exception with the help of an example. 5 OR Q1B_ When you need ordered container of things,which will be manipulated,use lists? 5 Q2 Answer the following questions. ‘A. Explain the use of global variable using an example. 5 B_ Explain the need of reduce with an example, 5 OR A Write a python program to check that whether the given number is positive, 5 negative or zero. B_ Write a python program to generate reverse number of given number. 5 Q3. Answer the following questions. ‘A. How to declare class and object in Python? 5 B_ Write a python program to print all prime numbers in given interval. 5 OR A. Write a python program to demonstrate class, local and instance variable. 5 B_ Explain following set functions with its syntax and example: 5 i. capitalize) ii. rstripQ Page 1of2 SECTION - 11 Q-4A_ Give the output of following code. 10 1 p=[aybie] q=[xy52] x2, y2 = zip(*zip(p, a) print x2 2. dif list=[[0]* 4 for iin range(2) ] print dif list 3 a=[1,"a",2,"b", "test", "exam" ] for af -1] in a: print a[-1] , 5 1=(,0,5),7,2) a,b,c,d=t print b[1] Q-4B_ Flatten anested list structure. 5 Example: if list =[1, 2,3], [4,5,[6,71]] then try to convert it in 1-dimensional 11, 2,3, 4, 5, 6, 7] OR Q-4B_ Write a python program to find factorial of number using recursion. 5 Q5_ Answer the following questions. A. Give syntax and example of following set functions: 5 i, discard) ii. clear() B_ Explain module with suitable example. 5 OR How dictionary can be created in python? 5 Write a python program to remove duplicate values using user defined function. 5 A B Q-6 Answer the following questions. A B Explain string slicing using proper examples. 5 Write python program to print Fibonacci series using recursion. 5 OR A Write python program to convert decimal number to binary using recursion, B_ Explain the features of python, 5 Page 2 of 2 KADI SARVA VISHWAVIDHYALAYA B.E. Semester VI Examination — April — 2015 CE 505 / IT 505 ~ PYTHON PROGRAMMING, DATE: 06/08/2015, ‘TIME: 10.30 AM to 1.30 PM. TOTAL MARKS: 70 Instructions: | Answer each section in separate answer sheet. 2 Use of scientific calculator is permitted. 3. All questions are Compulsory. 3 4 Indicate elearly, the options you attempt along with its respective question number. 5 Use the last page of main supplementary for rough work. SECTION-1 QIA the output of following code. 0 1 mylist=[[(1, 2} (3, 411, C15, 61, (7, 811] print mylist{ 1] (0) [0], mylist{=1] [0] [0] 2 print type(map(lambda x : x+2, range(0,4))) 3 list=[(),L], None, ‘None’,} print list{-1)[1] 4 st = set([32, 23, 47, 67)) s2 = set([23, 47, 14, 26]) s3 = set([67, 90, 32, 47]) print set.intersection(sI, s3, 2) 5. from collections import deque queue ~ deque((1,2,3.4,5]) val = queue.popleft(); 3 print val I = queue. pop(); print val Q-1.B_ Explain concept of multiple inheritance and method overriding with an example. OR Q-1B List out the features of python. Q2_ Answer the following questions. A\ Give the syntax, use and example of Ijust() and title(). 5 B_ Give the syntax, use and example of difference() and symmetric_difference(). 5 OR A. Differentiate between instance method and static method with an example. 5 B_ Differentiate between instance variable, class variable and local variable with an 5 example. Page 1of3 Q-3_ Answer the following questions. A. Suppose we have a list called list =[0.5, 45.6, [ [0.5, 34], 12], 45, (34, 45.6), 0]. 5 Process this list such that output list only contains unique items. (Hint: output=[0.5, 45.6, 34, 12, 45, 0)) B Demonstrate the concept of operator overloading with an example. 5 OR A What is the use of class method? How it can be declared and used in python 5 program? B_ What is the use of dictionary in python? What are the ways to define dictionary? 5 SECTION - II Q-4A Find out error(s) in the following code, if any and correct it. 10 1 tist=[1, 2, 3] listextend([4,5}) print list U1, 2,3] list.append(4,5) print list 3 data=([[ 1.21134] 0(5,61{7.81]] print dataf-t) [-1] [-1] 4 Pelambda X: X= 10 print F(10) Jal}, None, ‘None’,] print list{2][1] Q-4B Implement the concept of echo server and client using socket programming in 5 python OR Q-4B_ Implement the concept of time server and client using socket programming in 5 python. Answer the following questions. List out and explain ways of importing a module in a python file, 5 Explain the concept of default argument with an example. 5 OR >a > Write a python program to create customize exception for checking string length. If string length is more than 10 or less than 5 then customize exception must be thrown. B_ Explain filter() and reduce() with their syntax and example. s Page 2 of 3 Q-6 Answer the following questions. A. Give output of the following. 1 (abe!) 2 print type(t) t('abe')) print type(t) 2 print filter(lambda x : (x92) == 0 , range(-5,6)) 3 tuple2 = (231,'ert’) tuple3 = tuple2 + (746,) int emp(tuple2,tuple3) B_ What is the use of getter and setter method? Define the ways to implement it. OR ‘A. Give syntax and example of following string functions: 5 i. stripQ ii. joind) B_ How the concept of constructor and destructor can be implemented in python? Page 3 of 3

You might also like