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/ 12
[This question paper contains 12 printed pages.]
Your Roll No..2:
Sr. No. of Question Paper : 1672 G
Unique Paper Code + 2343012001
Name of the Paper Python Programming for
Data Handling
Name of the Course : Common Prog Group (DSE/
GE)
Semester :
Duration : 3 Hours Maximum Marks : 90
Instructions for Candidates
1. Write your Roll No. on the top immediately on receipt
of this question paper.
2. Attempt All questions from Section A.
3. Attempt any 4 questions from Section B.
4. All the parts of a question must be answered together.
Section A
) Mhat is a dictionary in python? Explain using an
.
example. aa (3)
P.T.O“Eg
1672 2
Sire output of the following code : '
Q)
Mn = (1,2,3,4,5,6,7,8,9,10]
r=0
for i in range(0, 10):
if (n[i]%2 == 0):
r += ci]
print(r)
ee 10 (3)
def func():
lv = 20
gv = 30
print(gv)
print(lv)
func()
print(gv)
LoMtite a function in python to find the sum and
maximum of three integers. (2)
(d) Explain the following functions of files in
python : (6)1672 3
G) Fscek()
Gi) ftellQ
Gii) freadlineQ,
(c) Differentiate between : (6)
(i_startswithQ) and endswith(,
(break and continue @
Gy Radiobutton and Checkbutton —
(f) Evaluate the following expressions : (4)
(i) abs(-5.4)
i math. floor(25.7)
(iii) x=2+9*((3*12)-8)/10
(iv) 5% 104+ 10-25 * 8//5
) What is the use of a layout manager in Tkinter?
Briefly discuss the ‘grid’ layout manager and the
purpose of ‘row’ and ‘column’ parameters.
(4)
Section B
2. Consider the code segment given below for a student
form :
yy
w1672
import tkinter as tk
root = tk.Tk() y
#Name of the Student
name_var = tk. StringVar(root)
name_inp = tk.Entry(root, textvariable=name_var)
#Roll Number of the Student
rollno_var = tk.IntVar(root)
rollno_var = tk.Entry(root, textvariable=rollno_var)
(@entity all the Tkinter Control Variables in the
code above. Write python code for adding a ‘Save"
(5)
button.
(b) Write a callback function ‘on_save’ for the ‘Save’
button which does the following :
(i) Collect ‘name’ and ‘rollno’ from the form
using ‘get’ and store it in a Python
dictionary object. (5)
(ii) Using the CSV DictWriter class, write the
students record (‘Name’, ‘Roll No’)
collected in a dictionary object to file
‘students.csv’. Create a new file if the file
doesn’t exist. Also write a header in the
‘students.csv’ file using the dictionary keys.
(5)1672 5
ae
Consider the code segment given below :
import tkinter as tk
window = tk.Tk()
myform = tk.Frame(window)
myform.grid()
tk.Label(myform, text="Welcome").pack()
tk.Entry(myform, text="Enter some Text").pack()
window.mainloop()
GY What is the widget hierarchy? Identify the
different widgets and their child widgets in
the code above. (S)
Gi) Prw the graphical user interface created
by the program. Sizes of widgets doesn’t
need to be precise but ensure that the
positioning of widgets relative to one
another is correct. (5)
(b) Choose the best option : (5)
(i) def f1Q:
x=15
print(x)
x=12
£10)
B.T.0.1672
(a) Error
(b) 12
(c) 15
(4) 1512
(ii) x = [i for i in range(3)]
for i in x:
print(i)
(a) 012
(b) Error
(c) 012012
(d) None of the mentioned
(iii) math.ceil(54.6)
(a) 54
(b) Error
(c) 55 —
(d) 54.5
(iv) 5 % 10+ 10 <50 and 29 >=29
(a) True
(b) False1672
conditio
code:
(c) Error
(d) None of the above,
(w T=0
count = 20
while count > 5:
T += count
count -= 1
print(T)
(a) Error
(b) 190
(c) 195 Tv
AAtout = et
(a) 196
4. (a) Write an assignment statement using a single
nal expression for the following if - else
()
if marks >=70:
remarks = ‘good’
else:
rerparks = ‘Average’
P.T.O.1672 8
(bWhat is the difference between a Mutable data
type and an Immutable data type? Explain giving
an example of cach type. (5)
(c) Write a python program to print the following
pattern : (5)
5. (a) Consider the following code segment: (5)
wiv 0-5-8
Msg = “Happy New Year 2024 as
ork we pe
Determine the output or indicate error on executing
the following statements :
(i) print(match.lower())
(ii) print(match[::2])
(iii) print(match[-4:-11])1672 9
(iy) print(mateh.index('n’))
(vy) print(mateh.partition(/*))
(b) Differentiate between the following (5)
(i) append() and extend()
(ii) x=10 and x==10
(c) Write a python function to return the sum of the
digits of a number, passed to it as an argument
(5)
6. (a) Consider the following function : (5)
def nfunc( a = 0, num = 1):
return a * num
Give the output produced for each of the following
function calls :
(i) nfunc(5)
(ii) nfunc(5, 6)
(ii) nfime(num = 7)
(iv) nfimc(num = 6, a = 5)
(v) nfunc(5, num = 6)
P.T.O1672 10
(b) Identify the error, if any, in the following code
segments = (5)
(i) #SET
grade= (“At”, “A”, “A-"}
grade 1 = grade + {1}
print(gradel)
print(grade[2:])
(ii) #FUNCTION
def example(a):
a=a+t'2
a=a*2
return a
example("hello")
(iii) 4TUPLE
t=([40,50], "Ram", [40,30])
{(0][J= "Ram"
print(t)rs
1672
(iv) for a in range(7, 20):
if (a = 6):
print EXITING”)
Continue
print(a)
(v) print(*%5d’, % 12345)
(c) Write short note on: (5)
(i) map and reduce operations
(ii) islower, lower, istitle functions of strings
7. (a) Write a python program to performs the following
operations : (5)
(i) Create a file ‘Filel.txt’ and write the
following text in it:
Python is a popular language
(ii) Read ‘filel.txt’ and copy the contents of
the file to output file ‘file2.txt’.
(b) Consider the file ‘vowels.txt’ having following
line : ()
aeiouAEIOU1672 12
The file is opened in ‘r+’ mode and the operations
below are performed sequentially. What will be
the output after cach operation?
(i) fwrite(*123457)
(ii) fread()
(iii) f.seek(0)
(iv) fread(5)
(v) f.read()
(c) What are the following functions used for: (5)
(i) eval function
(ii) append in lists
(iii) reverse in lists
(iv) isalpha in strings
(v) encode in strings
(1000)