Name:     ID: 
 
Email: 

Python Programming - Assessment 4

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

 1. 

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

 2. 

Python module needed to use math.pi.
a.
import turtle
c.
import random
b.
import math
d.
import time
 

 3. 

In a try / except / finally exception handling block, the finally block will execute regardless if the try block raises an error or not.
a.
true
b.
false
 

 4. 

In a try / except / finally exception handling block, you can have multiple except blocks.
a.
true
b.
false
 

 5. 

What is the output of the following code?

number = 5.0
try:
     r = 10/number
     print(r)
except:
     print(“Oops! Error occurred.”)

a.
2.0
c.
Oops! Error occurred.
b.
not defined
d.
2.0 Oops! Error occurred.
 

 6. 

Python module needed to use time.sleep.
a.
import turtle
c.
import random
b.
import math
d.
import time
 

 7. 

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

 8. 

Python module needed to draw graphics.
a.
import turtle
c.
import random
b.
import math
d.
import time
 

 9. 

Python statement needed to generate a random integer.
a.
random.shuffle
c.
random.randint
b.
random.randrange
d.
random.choice
 

 10. 

Opening a file in “a” mode.
a.
opens a file for appending at the end of the file
c.
opens a file for exclusive creation
b.
opens a file for writing
d.
opens a file for reading
 



 
         Start Over