2393 12 12 printed pages.
] 'E)
(i) try:
-~·
-
0/./2--,2-D:L-3-.._
Your Roll No .
f = opeh('."[Link]', 'r')
2393 G
~
except IOfirror:
Unique 2344001102
print("Problem with input output")
Name of the Paper Programming with Python
else:
printf("No problem with input output") Name of the Course Computer Science: Generic
Elective
(ii) try: Semester I
f = open([Link]', 'w') Duration : 3 Hours Maximum Marks 90
except IOError:
Instructions for Candidates
print("Problem with input output") "
else: l. Write your Roll No. on the top immediately on receipt
of this question paper.
print("No problem with input output")
2. Question 1 in Section A is compulsory.
(c) Write statements in Python to accept two strings 3. Attempt any 4 questions from Section B.
S l and S2 from the user. Subsequently, display
4. Answer all parts of a question together.
distinct characters in both the strings in ascending
order. (5)
Section - A
1. (a) Draw a flow chart to find whether a positive
integer is even or odd. (3)
(500) P.T.O.
2393 2 2393 11
(b) Construct logical expression for representing the (iii) total = 0
following condition : (3) total = total + x
print(total)
Rol!No should not be negative and Marks should
(iv) if age > 18
be in between 0 and 100.
print("Eligible for License")
(c) Identify valid/invalid identifiers from the
( c) Write a function in Python that accepts a list of
following:
integers L from the user. The function should count
(i) First Number and return the number of elements that are greater
than 50. (5)
(ii) Numberl
7. (a) Write a function in Python that takes a digit (from
(iii) Number#List
0 to 9) as an input parameter and returns the
(iv) Pass corresponding text in words. For example, on input
5, the function should return 'Five'. Use a
(v) Number
dictionary for mapping digits to their string
representation. (5)
(vi) Del (3)
(b) W h at w i 11 b e th e o u t p u t o f th e fo 11 o w in g
(d) List any 3 operators of dictionary that can be used
code segment if the file being opened does not
only with the keys of the dictionary. Give example
exist : (5)
of one operator with its usage. (3)
P.T.O.
2393 10 2393 3
(ii) tupl = (10) ( e) Consider a tuple t = ("Harry", "Jack", [ 40,3 5])
print([Link](l 0))
Indicate error (if any) in the following code
(iii) list I = (54, 76, 34, 'Hello', 42] segments else write no error. Justify your answer.
print(sum(listl))
(i) t[l] = "Rinni"
(iv) strl = "Hi, wow are you?"
print(t)
s trl [ 4] = 'h'
(ii) t[2][0] = 45
(v) dictl = {'A': 65, 'B': 66, 'A': 67}
print(t) (3)
print(dictl)
(f) Describe three modes used for opening a text
6. (a) Write a function that takes two files filel and
file. (3)
file2 as input. The function should read the contents
of file file I line by line and shou Id write them to
(g) Consider a dictionary : (3)
another file file2. Display the contents of file 2.
(6) papers= {'GEI': 'Python File', 'GE2': 'DBMS',
'GE3': 'Computer Networks', 'GE4': 'Information
(b) Identify the error(s) in the following: (4)
Security'}
(i) listl = ('Apple', 'Mango', 'Orange', 'Cherry'] What will be the output of the following function
list I [5] = 'Pineapple'
calls :
(ii) tuplel = (1, 'a', 4, 'r', 7,9)
(i) print([Link](' G ES'))
print(min(tuplel))
P.T.0.
2393 4 2393 9
(ii) print([Link]('GE5', "No such paper 5. (a) Write a function FnFactor() that accepts a number
exist")) as input parameter and print its factors. (4)
(h) Identify two exceptions that may be raised while (b) What will be the output of the following code
executing the following statement and justify your segments: (6)
answer. (3) I
1 (i) x = [l,2,3,4,5,6,7,8,9,10]
product = x/y
~
result = 0
(i) Consider a string : (3) for i in x:
strl = "SEC, Front End Web Design and if i%2 != 0:
Development" result += i
Find the output of the following statements: print(result)
(i) strl [17:] (ii) series= [i for i in range(l, 50) if i%5 == OJ
print(series)
(ii) strl[-len(strl) len(strl)]
( c) Identify the output/error (if any) for the following.
(j) Consider the following: (3)
Justify your answer if it is an error. (5)
names= ["Abhinav", "Riya", "Kirti", "Divya"]
(i) set 1 = {"Word", "Excel", "PowerPoint"}
rollno = (101, 104, 106, 109)
print(setl [2])
subject= ["Maths", "English", "Chemistry",
"Economics"]
P.T.O.
2393 8
2393 5
(iii) print(func(IA = 12))
What will be the output of the following
(iv) print(func(67, 20, 5)) statements:
(i) data= list(zip(names, rollno, subject))
4. (a) Write a function Fnreverse() that accepts a number
print(data)
from the user and print the reverse of the entered
number. (ii) [Link]()
(5)
print(names)
(b) Consider the following string :
(5)
Pnarne = "Programming with python"
Section - B
What will be the output of the following:
(i) [Link]('P') 2. (a) Write a function FnStr() in Python to accept a
string from the user. Replace all the consonants
(ii) [Link](' ')
in the given string with the symbol "#". Return
(iii) [Link]() the modified string from the function. (5)
(iv) [Link]('n') (b) Consider three sets:
(5)
(v) [Link] (' ') set!= {1,2,3}
set2 = { 4,5,6,2,3}
(c) Differentiate between copy() and deepcopy()
functions of the list, with the help of an example. set3 = {4,5,7,8,9,2}
(5)
What will be the output of the following:
P.T.O.
2393 7
2393 6
def fun ct():
(i) [Link](setl, set2, set3)
name = int(input("Enter your name"))
(ii) set [Link]([Link] (set3 ))
salary = 25000
(iii) [Link](set3, set2, setl) salary = salary + incentive
(iv) set3 .d ifference(set2 .difference( set 1)) info = name + salary
print(info)
(v) set3 .di fference(set2. un ion(set 1))
funct()
(c) Differentiate between extend() and append()
Identify and describe 3 exceptions that can be
functions of the list, with the help of an example
raised while executing the above function funct().
(5)
for each.
(c) What will be the output/error (if any) of the
3. (a) Write a function to print the following pattern:
following code segment : ( 4)
(5)
marks = 65
5 5 5 5 5 def func(marks, IA):
4 4 4 4 IA= 23
3 3 3 marks = marks + IA
2 2 return marks
1
(i) print(func(57))
(b) Consider the following function : (6)
(ii) print(func(53, 24))
P.T.0.