0% found this document useful (0 votes)
13 views7 pages

2024 Programming Using Python (DSC-1)

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)
13 views7 pages

2024 Programming Using Python (DSC-1)

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
You are on page 1/ 7
[This question paper contains 12 printed pages.] Sr. No. of Question Paper : Unique Paper Code Name of the Paper Name of the Course Semester Duration : 3 Hours Your Roll Nowssssseeseeees 1546 G 2342011101 Programming using Python (DSC-1) B.Sc. (1) Computer Science I Maximum Marks : 90 Instructions for Candidates 1. Write your Roll No. on the top immediately on receipt of this question paper. 2. Section A is compulsory. 3. Attempt any 4 questions from Section B. 4. Parts of a question must be answered together. P.T.O. 1546 2 1546 3 SECTION A (@ Explain any two access modes available for (Compulsory) file handling in python. Use suitable examples. ro) 1. (a) Give the pseudocode or flowchart for finding the (©) Determine output of the following code snippet largest of three numbers. @ @) (b) Give type of error in the statements given inyStr = ‘ihleD fo ytisrevin! below: °) _ mySte = mySte[::-1] print(myStr + “+ "110007" @=[1.2.31 ae print(len(myStr) Gxty (f) Write @ function studentData(n), that returns a Gi a] dictionary with keys as the student roll number and value as student name. The function should (c) Determine the output of following code. State the Gatusslatin anil sas fix all ilerations @ accept roll number and name, for n students, as oo input from the user. while a> 0: Example, the returned dictionary chould look like sum = sum + (n % 10) ** 3 {101: ‘Sahil’, 102: 'Sam',..} 6 n= n//10 print(sum) P.T.O. 1546 a 1546 5 (g) In the given code snippet, state the value of Ly (@ © = aunion(b) after execution of each statement Li = {10, 20, 30,20) Li.append(0) print) Li remove(20) print(Lt) (Liextend( aroma’ print(L1) (h) Consider sets a and b: 5, 12, 33, 14, 55) 101, 13, 14, 53, 16) @) @e=aad ii) ¢ = a.symmetric_difference(b) () Write « function factors(at) that returns a set of all the factors of the number nI. « SECTION B 2. (a) Write a python program which contains the following functicns o @) (@ readMe Titel) that prints the total number of lines present in file file Gi) copy(fitel, file2) that copies even lines of the file filel in file file2. Find the value of ¢ for each of the following statements : 1546 e (0) Evaluate the following expressions 2+3tS2HIO-6 @1>2<3 Gi) ~ (8) (iy) 8>>3 3. (a) Find the output of the following code = d= (RED'4, ‘GREEN’: 14, 'BLUE‘24} dkeys = list(d.keys) print(dkeys[0]) print(’blue’ in d) 4(ORANGE}] = 12 a{GREEN] += print(d) 1546 a 8) (b) Write a function process(str1) that performs the following ao) (i) Calculates the frequency of each character in the string strl, using dictionary type. Print this dictionary. ji) Function should return the string which has the worés in the reverse order. 6) Example: if str1 = ‘Best of luck Savita!’, the function should return the string ‘Savita! luck of Best 4, (@) State the value of y after each step: o y += x{9] + x9] PTO. 1546 8 5 y += x[-5] + x3] + x13) y += x(5] + xf2] + x2] y= y.partition( ') y = yl0] + '@ + “'oin(y[2]-split( )) print(y) (b) Describe the following string functions with examples ® (@ capitalized Gi) isdigitO i) upper) (iv) isalphad) (a) Consider the following set of statements: (7) import copy list! = (1, 2,03, 41] 1546 9 6 list2 = copy.copy(listl) list3 = copy.deepcopy(list!) list3{0] = 690 list1(2] [0] = 75 Find and justify the values of listl, list? and list. (b) Generate a list containing the cube of the odd numbers from 1 tom, using + ) () a user-defined function myCube(n) Gi) list comprehension (a) Determine the output of the following code: (7) xy=4,5 sum = 0 while (y > 0): P.T.O. 7 1546 10 ity & 1): sum = sum +x xexrl rint(x, y) print(sum) ‘1546 11 print(max(tl)) print(t1[1:3]) print(tl count(7)) 12[1]10]= 5 print(t2) 13 = U1 + tuple(India’y (b) Write a program that does the following checks ‘on the age entered by the user print(3) (6) (©) Define a class Drone that contains following data members : @ (@ age should not contain alphabets or special characters Gi) age should not be less than 21 Raise and handle appropriate exception(s). (a) Compute the output of the following code : = (1,2, 3, 7,9, 0, 5,7) 12 = (23, [24, 25)) Instance variables: droneld - id of drone Class variable: totalCount - for keeping count of ail the drones manufactured The clas shoud contain the following methods: oO © _init_() - initialize data members and Jntreusat total Covat Gi) gettaQ ~ returns droneld PTO. 1546 12 (iii) getTotalCount() - returns totalCount (iv) _del_() - to destroy the object and decrement the totalCount (500)

You might also like