Name:     ID: 
 
Email: 

Python Programming - Assessment 4

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

 1. 

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

 2. 

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

 3. 

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

 4. 

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

 5. 

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
 

 6. 

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

 7. 

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

 8. 

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

 9. 

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

 10. 

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



 
         Start Over