Name:     ID: 
 
Email: 

Python Programming Final Exam

Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 1. 

What is used to define a body of a loop?
a.
quotation
c.
curly braces
b.
parenthesis
d.
indentation
 

 2. 

Python statement needed to use math.pi?
a.
import os
c.
import random
b.
import math
d.
import sys
 

 3. 

The if..elif..else executes only one block of code among several blocks.
a.
It depends on expression used.
c.
False
b.
True
d.
There is no elif statement in Python
 

 4. 

Which of these would be used to loop through instructions exactly 10 times?
a.
If statement
c.
WHILE loop
b.
FOR loop
 

 5. 

Suppose a list with name test, contains 10 elements. You can get the 5th element from the test list using:
a.
test[‘5’]
c.
test[‘4’]
b.
test[4]
d.
test[5]
 

 6. 

Comments are ignored by the Python interpreter. What symbol is needed at the beginning of the comment?
a.
@
c.
< >
b.
#
d.
[ ]
 

 7. 

What is used to take input from the user in Python?
a.
input( )
c.
<>
b.
print( )
d.
scan( )
 

 8. 

Which Python statement will check to see if a is greater than or equal to b?
a.
if a >=b:
c.
if (a > b)
b.
if a>b:
d.
if a is greater than b
 

 9. 

A syntax error in code means:
a.
you have not used enough characters
c.
Python cannot find the file to pass the code to
b.
there was an error with your typing and code structure
d.
there was no defined index
 

 10. 

Which data type represents a whole number?
a.
Boolean
c.
Float
b.
String
d.
Integer
 

 11. 

Which term is used to describe expressions that result in the value of either true or false?
a.
Boolean
c.
Selection
b.
Concatenation
d.
Conditional
 

 12. 

Which of the following statements is true?
a.
the break statement terminates the loop containing it
c.
the continue statement is used to skip the rest of the code inside the loop
b.
the break and continue statements are almost always used with the if, if...else, and if...elif...else statements.
d.
All of the above.
 

 13. 

Which of the following is correct?
a.
A variable name can start with a digit
c.
Reserved words can be used as a variable name
b.
A variable name can have symbols like: @, #, $ etc.
d.
A variable name can start with a underscore
 

 14. 

What is the output of the following code?

while 4 = = 4:
       print(‘4’)
a.
4 is printed once
c.
4 is printed infinitely until program closes
b.
4 is printed four times
d.
Syntax error
 

 15. 

What is used to concatenate two strings in Python?
a.
, operator
c.
^ operator
b.
# operator
d.
+ operator
 

 16. 

The method to remove an entry from a dictionary is named?
a.
remove
c.
delete
b.
pop
 

 17. 

To obtain the length of a string, you can use which function?
a.
len( )
c.
index( )
b.
length_input( )
d.
length( )
 

 18. 

Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?
a.
tmpfile.read( )
c.
tmpfile.read(n)
b.
tmpfile.readlines(n)
d.
tmpfile.readline(n)
 

 19. 

In the following code, num is a ____?

num = ‘5’
a.
float
c.
integer
b.
boolean
d.
string
 

 20. 

Erases the contents of an existing file?
a.
outfile = open(“temp.txt”, “r”)
c.
outfile = open(“temp.txt”,”a”)
b.
outfile = open(“temp.txt”, “w”)
 



 
         Start Over