Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1. (a) Differentiate between mutable and immutable objects in Python language with example.

2
(b) Identify and write the name of the module to which the following functions belong: 1
(i) ceil() (ii) findall()
(c) Observe the following Python code very carefully and rewrite it after removing all 2
syntactical errors with each correction underlined.
DEF execmain() :
x= input(“Enter a number:”)
if (abs(x)=x) :
print “You entered a positive number”
else :
x=*-1
print “Number made positive:” x
execmain()
(d) 2

(e) Write the output of the following python program code: 3


def ChangeList () :
L=[]
L1=[]
L2=[]
for i in range (1, 10) :
L. append (i)
for i in range (10, 1, -2) :
L1. append(i)

1
for i in range (len (L1)) :
L2. append (L1[i] + L[i])
L2. append (len (L) – len (L1))
print (L2)
ChangeList ()
(f) Study the following program and select the possible output(s) from the options (i) to (iv) 2
following it. Also, write the maximum and minimum values that can be assigned to the
variable Y.
import random
X=random.random()
Y=random.randint (0, 4)
print (int (X), “:”, Y+int (X))
(i) 0:0
(ii) 1:6
(iii) 2:4
(iv) 0:3

2. (a) 2

(b) Write a Python function if the element in tuple is integer type then display the sum of 2
digits which are multiply by 3 in another tuple .

(c) Write a program using function to swap first half elements with second half element of 2
the list.
3. (a) Observe the following code and answer the questions that follow: 1
File= open (“Mydata”, “a”)

083/3
2
______________________ #Blank1
File.close ()

(i) What type (text/binary) of file is Mydata?


(ii) Fill in Blank1 with a statement to wrute “ABC” in the file “Mydata”.
(b) Write a function EUCount() in PYTHON, which should read each character of a text file 2
IMP.TXT, Should count and display the occurrences of alphabets E and U (including
small cases e and u too). For Example: If the file content is as follows :" Updated
information Is simplified by official websites. "The EUCount() function should display
the output as: E:4 U:1 Also Include functions to create the text file and display the entire
content of the text file
(c) Which of the following commands can be used to read the next line in a file using the 2
file object <tmpfile>?

A. tmpfile.read(n)
B. tmpfile.read()
C. tmpfile.readline()
D. tmpfile.readlines()

(d) Assuming somefile.txt contains: 4


This is line 1
This is line 2
This is line 3
This is line 4

(i) What is the output of the program snippet?


f1= open(‘somefile.dat’,’rb’)

f1.seek(10)
print (f1.read(4))

print(f.tell())
f1.seek(5,1)
print (f1.read(4))
print(f.tell())
f1.seek(-5,2)
print(f.tell())
print (f1.read(4))
f1.close()

3
(e) .WAF to read text of 5 line from text1.txt and and delete the 2nd line.
2
(f) WAF count number of alphabets, digits and special characters in text file. 4

4. (a) Which of the following statements correctly explain the function of seek() method? 2

A. tell the current position within the file.


B. indicate that the next read or write occurs from that position in a file.
C. determine if you can move the file position or not.
D. move the current file position to a different location at a defined offset.

(b) Write read and update binary file record of student using menu drive. Grades written 4
wrong by mistake so update grade to ‘A’ those students whose percentage greater than
90 and ‘B’ in between 80 and 90 rest ‘C’ have format.

[[1,neena,’A’,87],[2,geeta.’b’,93]……..]

(c) Which of the following statements correctly explain the function of tell() method? (1) 1

A. tells the current position within the file.


B. indicates that the next read or write will occur at that many bytes from the beginning
of the file.
C. move the current file position to a different location.
D. it changes the file position only if allowed to do so else returns an error.

083/3
4

You might also like