0% found this document useful (0 votes)
20 views8 pages

Programming With Python PYQ

This document is a question paper for a Programming With Python course, containing a total of 8 pages. It includes instructions for candidates, a variety of programming questions across two sections, and requires students to demonstrate their knowledge of Python programming concepts. The paper assesses understanding through coding tasks, function writing, and theoretical questions related to Python syntax and operations.

Uploaded by

classykomal902
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
20 views8 pages

Programming With Python PYQ

This document is a question paper for a Programming With Python course, containing a total of 8 pages. It includes instructions for candidates, a variety of programming questions across two sections, and requires students to demonstrate their knowledge of Python programming concepts. The paper assesses understanding through coding tasks, function writing, and theoretical questions related to Python syntax and operations.

Uploaded by

classykomal902
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
[This question paper contains 8 printed pages. | PARTH SHRIVASTAVA Sr. No. of Question Paper: 1243 D Unique Paper Code : 2344001102 Name of the Paper : Programming With Python Name of the Course : Computer Science: Generic SHRIVASTAVA Elective ~PARTH SHR Semester a 0 Duration : 3 Hours Maximum Marks : 90 Instructions for Candidates | 1. Write your Roll No. on the eR VK ReEAWA mn receipt of RAR HaSHRIVASTAV, 2. Question 1 in Section A is compulsory. 3. Attempt any 4 questions from Section B. 4. Answer all parts of a question together. HHRIVASTAVA | Section a = PARTH SHF 1. (i) What will be the output of the following code segment? (2) a=40 P.T.O. PARTH SHRIVASTAVA 1243 2 1 BARTH SHRIVASTAVA ey print(a,b) (ii) Give the output of the following code segment: 3 SHRIVASTAVA PARTH SHR for i in range(1, N+1): if i%2==0: continue for j in range (1, i+1): total+=1 PARTH SHRIVASTAVA print(total) (ii) Give the output of the following code segment: a=[l, 2, 3] b=a*2 print (b) (2) 7 5H RIVAST AV Avunction to count the »iPART.H wH F in a string (3) (vy) Evaluate the following expressions (5) (@) int (4.00 (2.0+2.0)) PARTH SHRIVASTAVA 1243 3 Gi) X=249%(3#12) gyi19 PARTE SHRIVASTAVA (iv) 2** (3**2) (v) (2**3) #eD (vi) Iden tify and Rectif tror (if any) in a a i ctify the e ( yi RIV ASTAY, ello py python" PA RTH S HF 6] ="s" (vii) Write a functi : on that accepts two nu returns its average, » mbers and (2) (viii) Identify valid/i ifi following Invalid identifiers from the (3) PAR FEPSHRIVASTAVA (ii) 2nd_string (iti) Foo (iv) _int_ (v) String% HRIVASTAVA PARTH SHR (ix) What is the type of arguments used in the definition of function add(). Write the output that will be produced on the execution of the following code segment: (5) P.T.O. PARTH SHRIVASTAVA 1243 4 def add(a=3, b=5, c=7): PARTPE SHRIVASTAVA print(add()) print(add(7)) print(add(6,8)) print(add(c=9)) (x) Design a flow chart to display the largest factor H RIVASTAV RA” number. PARTH yy Section B Write a function fl(n1,n2,n3) which returns the minimum and maximum of three arguments i nl, n2, and n3. PART H' SHRIVASTAVA def f(x, 1=[]): for i in range(x) : 2. (a) [Link](i*i) print(1) f(2) HRIVASTAMAD PARTH SHF £(3) (c) Write a function named FnSeriesSum(), which accepts an integer argument (n) to calculate the sum of the first n terms of the following series PARTH SHRIVASTAVA - - 1243 5 {PARI HeSRIVASTAVA® 3. (a) Use the given list L to find the output for the following methods. Write down the updated content of list L after applying each method. (5) 12, 2, 4, 3] IRIVAS TAM Asa PARTH SHR (ii) [Link](2) (iii) [Link](12) (iv) [Link](2,15) (v) [Link](2) (b) Write a function FnCommon() to find ae BART Serta An re needs to return the computed list L3. (c Write a Python function, with appropriate comments, that takes the name and age of a person as input and displays an appropriate message whether the person is eligible to vote or not based on age where minimum age for voting is 18 years. Also check that input name IRIVAS TAG Ase none" PARTHE SHR 4. (a) Write a function in Python to generate the following two patterns: (6) @ * P.T.O. PARTH SHRIVASTAVA | 1243 6 koe OK PARTH SHR]VASTAVA (ii) 4321 321 21 1 (b) Consider the following strings to find the i H RIVASTAAFA Slowing print statemgatg\ RT | s= ‘abcdefxyyzxyzxzxyy' (i) print([Link]) (ii) print([Link] ('xy')) (iii) print([Link]('cd’)) PAR FH SHRIVASTAVA (v) print ([Link] ('x')) (c) Rewrite the following code using for loop: (4) i=10 while(i>0): print(‘i=", i) HRIVASTAVA PARTH SHF 5. (a) Consider tuple T1=(12, 3, 45, 'Hockey', ‘Anil’, ('a', 'b')) to answer the following: (5) (i) Display the first element of 'T1’. PARTH SHRIVASTAVA - 1243 7 = (ii) Display the last element of 'TI'. RAR Stupor Vad aA (iv) Display 'b' from tuple 'T!'. (v) Display 'Anil' from tuple 'Tl’. (b) Write a function that takes two files, [Link] and [Link], as input. The function must read RIVAST AY AAS them to ancter RCN aE SH Display the content of file [Link]. Use appropriate exceptions for file handling. (5) (c) Write a function to print every character of a string entered by the user in a new line using the for loop. Also, display total number a characters in the string at the end. (5) PARTH SHRIVASTAVA 6. (a) What will be the output of the following code segment? (5) for letter in ‘programming with python’: if letter=="a' or letter== continue RIVASTAV letter:', letter) PARTH SH F (b) Write a function that accepts a list (L) of 10 elements to find the frequency of each distinct element in L. Use dictionary to store element and its count in key- value pair form. Also, display the elements with maximum count using dictionary. (6>4) PARTH SHRIVASTAVA £243 8 a roll iy the ” PAB STEN HANH following dictionary D in which key represe roll number and value is name. (2) D={1: 'Amit', 2: "Sumit', 5: 'Kavita’} (b) (i) Find the output of the following code: (2+1) HRIVASTAVA,. PARTH SHF print(5/x) except ZeroDivisionError: print("except block") else: print("else block") finally print("finally block") ! PARTH SHRIVASTAV (ii) What error is returned by the following statement if file “[Link]” does not exist? feopen("[Link]") (c) Write two differences between lists and tuples? Give one example showing their usage. (4) d) Write a user-defined function SUMSQUARES(n) HRIVASTAY on that accepts a uPAR RHISHF argument. The function returns’ the ‘stm squares of the first n numbers. Also, write statement to call this function for n=S and print the returned value. (6) (500) PARTH SHRIVASTAVA

You might also like