Exercises
Contents
9.3. Exercises#
9.3.1. Exercise 1#
Which one of the following modes of opening a file will overwrite all the contents of the file?
'w'
'a'
'r+'
# write your answer here as a comment
9.3.2. Exercise 2#
Which mode of opening would you use for reading a file?
'r'
'a'
'r+'
# write your answer here as a comment
9.3.3. Exercise 3#
Which error will correspond to passing an integer to a function when the function expects a string??
'BaseError'
'ValueError'
'TypeError'
# write your answer here as a comment
9.3.4. Exercise 4#
Write the following content into a file called 'exercise4.txt'
:
“In this case, no exception was raised, as a result the code block in the try statement was executed successfully. After it was finished, the control went to the finally block, printing the statement and terminating.”
# write your code here
9.3.5. Exercise 5#
Try to read and print in the screen the contents of the file you created in Exercise 4.
# write your code here