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 concatenate two strings in Python?
a.
, operator
c.
+ operator
b.
# operator
d.
^ operator
 

 2. 

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

 3. 

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

 4. 

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

 5. 

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

 6. 

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
 

 7. 

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

 8. 

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

 9. 

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

 10. 

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.readlines(n)
c.
tmpfile.read(n)
b.
tmpfile.read( )
d.
tmpfile.readline(n)
 

 11. 

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

 12. 

What is the output of the following code?

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

 13. 

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

 14. 

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

 15. 

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

 16. 

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

 17. 

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

 18. 

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

 19. 

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

 20. 

In the following code, num is a ____?

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



 
         Start Over