PYTHON CODING FREQUENTLY TESTED ACTUAL EXAM
QUESTIONS WITH CORRECT ANSWERS
Question 1.
for / in
ANSWER
(Chapter 8) What are the Python keywords used to construct a loop to iterate through a list?
Question 2.
Indent the line below the if statement
ANSWER
(Chapter 3)
What do we do to a Python statement that is immediately after an if statement to indicate that
the statement is to be executed only when the if statement is true?
Question 3.
42
ANSWER
i. (Chapter 6) What does the following Python program print out?
ii. x = '40'
iii. y = int(x) + 2
iv. print y
Question 4.
6
5
4
3
Done!
ANSWER
i. (Midterm) What is the output of this code?
ii. n = 6
iii. while True:
, iv. print n
v. if n == 3: break
vi. n = n - 1
vii. print 'Done!'
Question 5.
12
ANSWER
i. (Midterm) For the following Python program, what will it print out?
ii. x = 0
iii. for value in [3, 41, 12, 9, 74, 10] :
iv. if value < 10 :
v. x = x + value
vi. print x
Question 6.
Depending on the value of x, either all three of the print statements will execute or none of the
statements will execute
ANSWER
(Chapter 3)What is true about the following code segment:
i. if x == 5 :
ii. print 'Is 5'
iii. print 'Is Still 5'
iv. print 'Third 5'
,Question 7.
6
ANSWER
i. (Chapter 8) What does the following Python code print out?
ii. a = [1, 2, 3]
iii. b = [4, 5, 6]
iv. c = a + b
v. print len(c)
Question 8.
Associative arrays
ANSWER
(Chapter 9) What is a term commonly used to describe the Python dictionary feature in other
programming languages?
Question 9.
You have most likely mixed tabs and spaces in the file
ANSWER
(Chapter 3)
You look at the following text:
if x == 6 :
print 'Is 6'
print 'Is Still 6'
print 'Third 6'
It looks perfect but Python is giving you an 'Indentation Error' on the second print statement.
What is the most likely reason?
Question 10.
stop
ANSWER
(Chapter 2) Which of the following variables is the "most mnemonic"?
QUESTIONS WITH CORRECT ANSWERS
Question 1.
for / in
ANSWER
(Chapter 8) What are the Python keywords used to construct a loop to iterate through a list?
Question 2.
Indent the line below the if statement
ANSWER
(Chapter 3)
What do we do to a Python statement that is immediately after an if statement to indicate that
the statement is to be executed only when the if statement is true?
Question 3.
42
ANSWER
i. (Chapter 6) What does the following Python program print out?
ii. x = '40'
iii. y = int(x) + 2
iv. print y
Question 4.
6
5
4
3
Done!
ANSWER
i. (Midterm) What is the output of this code?
ii. n = 6
iii. while True:
, iv. print n
v. if n == 3: break
vi. n = n - 1
vii. print 'Done!'
Question 5.
12
ANSWER
i. (Midterm) For the following Python program, what will it print out?
ii. x = 0
iii. for value in [3, 41, 12, 9, 74, 10] :
iv. if value < 10 :
v. x = x + value
vi. print x
Question 6.
Depending on the value of x, either all three of the print statements will execute or none of the
statements will execute
ANSWER
(Chapter 3)What is true about the following code segment:
i. if x == 5 :
ii. print 'Is 5'
iii. print 'Is Still 5'
iv. print 'Third 5'
,Question 7.
6
ANSWER
i. (Chapter 8) What does the following Python code print out?
ii. a = [1, 2, 3]
iii. b = [4, 5, 6]
iv. c = a + b
v. print len(c)
Question 8.
Associative arrays
ANSWER
(Chapter 9) What is a term commonly used to describe the Python dictionary feature in other
programming languages?
Question 9.
You have most likely mixed tabs and spaces in the file
ANSWER
(Chapter 3)
You look at the following text:
if x == 6 :
print 'Is 6'
print 'Is Still 6'
print 'Third 6'
It looks perfect but Python is giving you an 'Indentation Error' on the second print statement.
What is the most likely reason?
Question 10.
stop
ANSWER
(Chapter 2) Which of the following variables is the "most mnemonic"?