0% found this document useful (0 votes)
162 views4 pages

Q1

The document contains 15 multiple choice questions about Python concepts like functions, recursion, files and CSV files. The questions cover topics such as the output of code snippets, the definition of recursion, function headers, opening and writing to files, and determining if functions are tail recursive. Answers to the questions are needed to test knowledge of common Python programming concepts.

Uploaded by

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

Q1

The document contains 15 multiple choice questions about Python concepts like functions, recursion, files and CSV files. The questions cover topics such as the output of code snippets, the definition of recursion, function headers, opening and writing to files, and determining if functions are tail recursive. Answers to the questions are needed to test knowledge of common Python programming concepts.

Uploaded by

Rakesh Sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Q.

1- Find out the output of the following operations: [1]


>>> 9//-4
i. 2
ii. -3
iii. 3
iv. -2.25
Q.2- Which of these is not true about recursion? [1]
i. Recursion is a function, calling itself again and again.
ii. Recursion is defining anything in terms of itself.
iii. Recursive calls take up less memory.
iv. Recursions implemented by dividing the recursive problem into two itself.
Q.3- Write the output of the following code [1]
def inner():
print(“Inner x is”,x)
x=20
print(“outside x is”, x)
inner()
Q.4-Which of the following items are present in the function header? [1]

A. function name
B. parameter list
C. return value
D. Both A and B
Q.5-What is called when a function is defined inside a class? [1]

A. class
B. function
C. method
D. module
Q.6-What is a recursive function? [1]

A. A function that calls other function.


B. A function which calls itself.
C. Both A and B
D. None of the above
Q.7-Which of the following is the use of id() function in python? [1]

A. Id() returns the size of object.


B. Id() returns the identity of the object.
C. Both A and B
D. None of the above
Q.8-Which of the following function headers is correct? [1]

A. def fun(a = 2, b = 3, c)
B. def fun(a = 2, b, c = 3)
C. def fun(a, b = 2, c = 3)
D. def fun(a, b, c = 3, d)
Q.9-How many objects and reference variables are there for the given Python code? [1]

class A:
print("Inside class")
A()
A()
obj=A()
A. 2 and 1
B. 3 and 3
C. 3 and 1
D. 3 and 2
Q.10- CSV File
1, AKSHAY, XII, A
2,ABHISHEK, XII, A
3,ARVIND, XII, A
4,RAVI, XII, A
5,ASHISH, XII ,A
Incomplete Code
import_____ #Statement-1
fh = open(_____, _____, newline='') #Statement-2
stuwriter = csv._____ #Statement-3
data = []
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION']
data.append(header)
for i in range(5):
roll_no = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
Class = input("Enter Class : ")
section = input("Enter Section : ")
rec = [_____] #Statement-4
data.append(rec)
stuwriter. _____ (data) #Statement-5
fh.close()
i. Identify the suitable code for blank space in line marked as Statement-1. [1]
a) csv file
b) CSV
c) csv
d) Csv
ii. Identify the missing code for blank space in line marked as Statement-2? [1]
a) "School.csv","w"
b) "Student.csv","w"
c) "Student.csv","r"
d) "School.csv","r"
iii. Choose the function name (with argument) that should be used in the blank [1]
space of line marked as Statement-3
a) reader(fh)
b) reader(MyFile)
c) writer(fh)
d) writer(MyFile)
iv. Identify the suitable code for blank space in line marked as Statement-4. [1]
a) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION'
b) ROLL_NO, NAME, CLASS, SECTION
c) 'roll_no','name','Class','section'
d) roll_no,name,Class,sectionc) co.connect()
v. Choose the function name that should be used in the blank space of line marked as Statement-
5 to create the desired CSV File? [1]
a) dump()
b) load()
c) writerows()
d) writerow()
Q.11- Which of the following commands is used to open the file
“STUDENT.DAT” for writing only in binary format? (marked as #1 in the
Python code)

a. F= open("STUDENT.DAT",'wb')

b. F= open("STUDENT.DAT",'w')

c. F= open("STUDENT.DAT",'wb+')

d. F= open("STUDENT.DAT",'w+')

Q.12-Which of the following statements correctly explain the function of


seek() method?

a. tells the current position within the file.

b. determines if you can move the file position or not.

c. indicates that the next read or write occurs from that position in a file.

d. moves the current file position to a given specified position

Q.13-5. What will be the output of the following Python code?

def test(i,j):
if(i==0):
return j
else:
return test(i-1,i+j)
print(test(4,7))
a) 13
b) 7
c) Infinite loop
d) 17

Q.14. Observe the following Python code?

def a(n):
if n == 0:
return 0
else:
return n*a(n - 1)
def b(n, tot):
if n == 0:
return tot
else:
return b(n-2, tot-2)
a) Both a() and b() aren’t tail recursive
b) Both a() and b() are tail recursive
c) b() is tail recursive but a() isn’t
d) a() is tail recursive but b() isn’t

Q.15-

You might also like