Name:     ID: 
 
Email: 

Python Programming - Assessment 4

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

 1. 

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

 2. 

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

 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. 

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

 5. 

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”)
 

 6. 

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 Oops! Error occurred.
c.
2.0
b.
Oops! Error occurred.
d.
not defined
 

 7. 

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

 8. 

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

 9. 

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

 10. 

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



 
         Start Over