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

Python Foundation Level Exam Questions

The document is a question paper for a computer-based exam on 'Foundation Level: Introduction to Python' consisting of 17 questions. It includes multiple-choice questions (MCQs), multiple select questions (MSQs), and short answer questions (SA) covering various Python programming concepts. The paper also provides instructions and options for each question, along with correct and incorrect answer indicators.

Uploaded by

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

Python Foundation Level Exam Questions

The document is a question paper for a computer-based exam on 'Foundation Level: Introduction to Python' consisting of 17 questions. It includes multiple-choice questions (MCQs), multiple select questions (MSQs), and short answer questions (SA) covering various Python programming concepts. The paper also provides instructions and options for each question, along with correct and incorrect answer indicators.

Uploaded by

kumarsam4560
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Question Paper Preview

Notations :
[Link] shown in green color and with icon are correct.
[Link] shown in red color and with icon are incorrect.

Change Font Color : No


Change Background Color : No
Change Theme : No
Help Button : No
Show Reports : No
Show Progress Bar : No

Intro to Python
Section Id : 640653124250
Number of Questions : 17
Section Marks : 50
Maximum Instruction Time : 0

Question Number : 1 Question Id : 6406531851629 Question Type : MCQ


Correct Marks : 0
Question Label : Multiple Choice Question
THIS IS QUESTION PAPER FOR THE SUBJECT "FOUNDATION LEVEL : INTRODUCTION TO
PYTHON (COMPUTER BASED EXAM)"

ARE YOU SURE YOU HAVE TO WRITE EXAM FOR THIS SUBJECT?
CROSS CHECK YOUR HALL TICKET TO CONFIRM THE SUBJECTS TO BE WRITTEN.

(IF IT IS NOT THE CORRECT SUBJECT, PLS CHECK THE SECTION AT THE TOP FOR THE SUBJECTS
REGISTERED BY YOU)
Options :
6406536002494. YES
6406536002495. NO
Question Number : 2 Question Id : 6406531851630 Question Type : MCQ
Correct Marks : 3
Question Label : Multiple Choice Question
Consider the following functions:

def p(n):
if n < 10:
return 1
return 1 + p(n // 10)
def q(n):
if n < 10:
return n
return n % 10 + q(n // 10)
def r(n):
if n <= 1:
return 1
return n * r(n - 1)

Which of the following function calls returns the number of digits in 50!, where n! is the
factorial of n?

Options :
6406536002496.
p(q(50))

6406536002497.
q(r(50))

6406536002498.
p(r(50))

6406536002499.
r(q(50))

6406536002500.
r(p(50))
Question Number : 3 Question Id : 6406531851631 Question Type : MCQ
Correct Marks : 3
Question Label : Multiple Choice Question
Consider the following code snippet that writes student details to a CSV file named
"[Link]":

def save_data(data):
f = open('[Link]', 'w')
[Link]('Name,Salary\n')
for i in range(len(data)):
emp, sal = data[i]
row = f'{emp},{sal}'
if i != len(data) - 1:
row = row + '\n'
[Link](row)
[Link]()
data = [
('Alice', 75000), ('Bob', 64000), ('Charlie', 82000),
('Diana', 71000), ('Eve', 69000)
]

If the save_data(data) function is called with the list data as shown above, what will be
the contents of the file "[Link]"?

Options :
6406536002501.

Name,Salary
Alice,75000
Bob,64000
Charlie,82000
Diana,71000
Eve,69000

6406536002502.

Alice,75000
Bob,64000
Charlie,82000
Diana,71000
Eve,69000

6406536002503.

Salary,Name
Alice,75000
Bob,64000
Charlie,82000
Diana,71000
Eve,69000

6406536002504.

Name
Salary
Alice,75000
Bob,64000
Charlie,82000
Diana,71000
Eve,69000

6406536002505.

Salary,Name
75000,Alice
64000,Bob
82000,Charlie
71000,Diana
69000,Eve

Question Number : 4 Question Id : 6406531851632 Question Type : MCQ


Correct Marks : 3
Question Label : Multiple Choice Question
What will be the output of the following Python code?

string1 = 'database'
string2 = 'baseball'
L = []
for i in range(len(string1)):
for j in range(len(string2)):
if string1[i] == string2[j]:
[Link](string1[i])
break
else:
continue
print(L)

Options :
6406536002506.

['a', 'a', 'b', 'a', 's', 'e']

6406536002507.

['a', 't', 'a', 'b', 'a', 's', 'e']

6406536002508.

['a', 'b', 'a', 's', 'e']

6406536002509.

['a', 'a', 'b', 's', 'e']


Question Number : 5 Question Id : 6406531851633 Question Type : MCQ
Correct Marks : 3
Question Label : Multiple Choice Question
What is the output of the following snippet of code?

sentence = 'python,is,fun,and,learning,python,is,great'
D = dict()
for word in [Link](','):
for char in word:
if char not in D:
D[char] = 0
D[char] += 1
mchar, mval = '', 0
alpha = 'abcdefghijklmnopqrstuvwxyz'
for char in alpha:
if char not in D:
continue
if D[char] >= mval:
mval = D[char]
mchar = char
print(mchar)

Options :
6406536002510.

6406536002511.

6406536002512.

6406536002513.

p
Question Number : 6 Question Id : 6406531851634 Question Type : MCQ
Correct Marks : 3
Question Label : Multiple Choice Question
If n is a positive integer, what does the following snippet compute?

Q = [x for x in range(1, 3 * n + 1) if x % 3 == 0]
print(sum(Q))

Options :
6406536002514.
1+2+3+…+n
6406536002515.
3+6+9+…+3n
6406536002516.
1+2+3+…+3n
6406536002517.
1+3+5+…+(2n+1)
6406536002518.
1+3+5+…+(3n+1)
Question Number : 7 Question Id : 6406531851635 Question Type : MCQ
Correct Marks : 3
Question Label : Multiple Choice Question
Consider the following snippets of code:

Code-1

T = (4, 5, 6)
T[0] = 10

Code-2

S = set()
[Link](2)

Code-3

L = []
[Link](3)

Select the most appropriate statement.

Options :
6406536002519.
Only code-1 will throw an error in line-2
6406536002520.
Only code-2 will throw an error in line-2
6406536002521.
Only code-3 will throw an error in line-2
6406536002522.
Code-1 and Code-2 will throw an error line-2
6406536002523.
Code-2 and Code-3 will throw an error in line-2
6406536002524.
All three code snippets will throw an error in line-2
Question Number : 8 Question Id : 6406531851636 Question Type : MSQ
Correct Marks : 3 Max. Selectable Options : 0
Question Label : Multiple Select Question
employees is a list of tuples. Each tuple is of the form (name, salary) . Select all snippets
of code that create a list high_earners that contains the names of employees whose
salary is above 70,000. A sample list employees and the expected output is given below.
You can assume that employees is already available to you.

Sample Input

employees = [
('Alice', 75000), ('Bob', 64000), ('Charlie', 82000),
('Diana', 71000), ('Eve', 69000)
]

Sample Output

['Alice', 'Charlie', 'Diana']

Options :
6406536002525.

high_earners = [name for (name, salary) in employees if salary > 70000]


print(high_earners)

6406536002526.

high_earners = []
for (name, salary) in employees:
if salary > 70000:
high_earners.append(name)
print(high_earners)

6406536002527.

high_earners = [name if salary > 70000 for (name, salary) in employees]


print(high_earners)

6406536002528.

high_earners = [name for (name, salary) in employees]


print(high_earners)
Question Number : 9 Question Id : 6406531851637 Question Type : MSQ
Correct Marks : 3 Max. Selectable Options : 0
Question Label : Multiple Select Question
Consider the following snippet:

f = open('[Link]', 'r')
D = dict()
for line in f:
name, department, salary = [Link]().split(',')
salary = int(salary)
if name not in D:
D[name] = dict()
D[name][department] = salary
print(D)

This code produces the given output:

{'Alice': {'HR': 70000, 'IT': 80000}, 'Bob': {'Finance': 65000, 'IT': 72000}}

Which of the following could be the contents of the file [Link] ? Select all
possible answers. Note that dictionaries store keys from left to right in the order in
which they are inserted. Once a key has been inserted into a dictionary, its order with
respect to other keys doesn't change, unless it is deleted and reinserted.

Options :
6406536002529.

Alice,HR,70000
Bob,Finance,65000
Alice,IT,80000
Bob,IT,72000

6406536002530.

Alice,HR,70000
Bob,Finance,66000
Alice,IT,80000
Bob,IT,72000
Bob,Finance,65000

6406536002531.

Bob,Finance,65000
Bob,IT,72000
Alice,HR,70000
Alice,IT,80000

6406536002532.

Alice,IT,80000
Alice,HR,70000
Bob,Finance,65000
Bob,IT,72000
Question Number : 10 Question Id : 6406531851638 Question Type : MSQ
Correct Marks : 3 Max. Selectable Options : 0
Question Label : Multiple Select Question
Consider the following snippet of code:

def analyze_string(t, k):


freq = {}
for ch in t:
freq[ch] = [Link](ch, 0) + 1

is_unique = all(c < k for c in [Link]())

if is_unique:
print(True)
else:
print(False)

if input_str.isdigit():
print(True)
else:
print(False)

analyze_string(input_str, 2)

input_str is a string variable that has already been defined. The above code runs
without any errors. The output when the code given above is executed is as follows:

True
True

Which of the following statements are True? Note that your answer should hold for any
value of the string input_str that results in the above output.

Options :
6406536002533.
input_str contains only numeric characters

6406536002534.
input_str could contain alphabets

6406536002535.
The first character of input_str occurs exactly two times
6406536002536.
All elements of input_str occur exactly one time
6406536002537.
All elements in input_str occur at least two times.
Question Number : 11 Question Id : 6406531851639 Question Type : SA
Correct Marks : 3
Question Label : Short Answer Question
What is the output of the following snippet of code?

def g(x, y):


if x == 1:
return 0
return 1 + g(x // y, y)
print(g(1024, 2))

Response Type : Numeric


Evaluation Required For SA : Yes
Show Word Count : Yes
Answers Type : Equal
Text Areas : PlainText
Possible Answers :
10

Question Number : 12 Question Id : 6406531851640 Question Type : SA


Correct Marks : 3
Question Label : Short Answer Question
What is the output of the following snippet of code?

total = 0
errors = 0
for s in ['5', '2.5', '7', '8']:
try:
n = int(s)
total += n
except:
errors += 1
total += 5
print(total + errors)

Response Type : Numeric


Evaluation Required For SA : Yes
Show Word Count : Yes
Answers Type : Equal
Text Areas : PlainText
Possible Answers :
26
Question Number : 13 Question Id : 6406531851641 Question Type : SA
Correct Marks : 3
Question Label : Short Answer Question
What is the output of the following snippet of code?

total = 0
num = 10
while num <= 20:
count = 0
for i in range(1, num + 1):
if num % i == 0:
count += 1
if count == 2:
total += num
num += 1
print(total)

Response Type : Numeric


Evaluation Required For SA : Yes
Show Word Count : Yes
Answers Type : Equal
Text Areas : PlainText
Possible Answers :
60
Question Number : 14 Question Id : 6406531851642 Question Type : SA
Correct Marks : 3
Question Label : Short Answer Question
Consider the following snippet of code:

L = [2, 3, 4]
S = []
T=0
i=0
while i < len(L):
S += L[:i] + L[i:]
for j in S:
T += j
i += 1

What will be the value of T at the end of execution of the above code?

Response Type : Numeric


Evaluation Required For SA : Yes
Show Word Count : Yes
Answers Type : Equal
Text Areas : PlainText
Possible Answers :
54

Question Number : 15 Question Id : 6406531851643 Question Type : SA


Correct Marks : 3
Question Label : Short Answer Question
What is the output of the following snippet of code?

def doSomething(x, y):


if x < y:
return 0
return 1 + doSomething(x // y, y)
log1 = doSomething(81, 3)
log2 = doSomething(64, 2)
log3 = doSomething(125, 5)
print(log1 + log2 + log3)

Response Type : Numeric


Evaluation Required For SA : Yes
Show Word Count : Yes
Answers Type : Equal
Text Areas : PlainText
Possible Answers :
13
Question Id : 6406531851644 Question Type : COMPREHENSION Sub Question Shuffling
Allowed : No Group Comprehension Questions : No Question Pattern Type : NonMatrix
Question Numbers : (16 to 17)
Question Label : Comprehension
You are inside the lift of a building. There are 8 levels in the building:

[−3,−2,−1,0,1,2,3,4]

The number 0 is the ground floor. Positive numbers correspond to floors above the
ground floor, negative numbers correspond to basement levels below the ground floor.
The lift has only two buttons. The button U will take you one level up and the button D
will take you one level down. You make a sequence of presses.

# presses contains the sequence of button presses made by you


presses = 'UDDUUUDDUDU'
floor = 0
index = 0
while index < len(presses):
char = presses[index]
if char == 'U':
floor += 1
elif char == 'D':
floor -= 1
if floor == 2:
print(index + 1)
break
index += 1

Based on the above data answer the subsequent questions.

Sub questions

Question Number : 16 Question Id : 6406531851645 Question Type : MCQ


Correct Marks : 2
Question Label : Multiple Choice Question
What is the given code snippet printing?

Options :
6406536002543.
It prints the number of button presses after which you reach the floor 2 for the first
time.
6406536002544.
It prints the number of times you cross the floor 2.
6406536002545.
It prints the final floor level after all the button presses.
6406536002546.
None of these.

Question Number : 17 Question Id : 6406531851646 Question Type : SA


Correct Marks : 2
Question Label : Short Answer Question
What is the output of this snippet of code?

Response Type : Numeric


Evaluation Required For SA : Yes
Show Word Count : Yes
Answers Type : Equal
Text Areas : PlainText
Possible Answers :
6
Question Id : 6406531851647 Question Type : COMPREHENSION Sub Question Shuffling
Allowed : No Group Comprehension Questions : No Question Pattern Type : NonMatrix
Question Numbers : (18 to 19)
Question Label : Comprehension
Consider the following snippet:

def ProcedureOne(M):
n = len(M)
for i in range(n):
temp = M[i][i]
M[i][i] = M[i][-i - 1]
M[i][-i - 1] = temp
return M
def ProcedureTwo(M):
p=1
n = len(M)
for i in range(n):
p *= M[i][i]
return p
M = [[2, 4, 6], [8, 10, 12], [14, 16, 18]]
P = ProcedureOne(M)
print(P)
print(ProcedureTwo(P))

Based on the above code answer the subsequent questions.

Sub questions

Question Number : 18 Question Id : 6406531851648 Question Type : MCQ


Correct Marks : 2
Question Label : Multiple Choice Question
What is the first line of output?

Options :
6406536002548.

[[6, 4, 2], [8, 10, 12], [18, 16, 14]]

6406536002549.

[[2, 4, 6], [8, 10, 12], [14, 16, 18]]

6406536002550.

[[14, 16, 18], [8, 10, 12], [2, 4, 6]]

6406536002551.

[[2, 6, 4], [8, 12, 10], [14, 18, 16]]


Question Number : 19 Question Id : 6406531851649 Question Type : SA
Correct Marks : 2
Question Label : Short Answer Question
What is the second line of output?

Response Type : Numeric


Evaluation Required For SA : Yes
Show Word Count : Yes
Answers Type : Equal
Text Areas : PlainText
Possible Answers :
840

You might also like