ENGR 102 Exam 2 Questions and
Answers Graded A+
File I/O - Correct answer-<fileID> = open("<File Name>", "<designator>")
File I/O: what is the designator for? - Correct answer-Designator is either "r" for
reading or "w" for writing to a file
Part 1) Functions available after successfully opening a file - Correct answer-to
read a line from a file that is open for reading: readline( ).
*Syntax for readline( ) function:
<string variable> = <fileID>.readline()
This returns a string from where the file pointer is at the beginning of the call until
a newline character is found.
Part 2) Functions available after successfully opening a file - Correct answer-If we
successfully open a file for writing,
©COPYRIGHT 2025, ALL RIGHTS RESERVED 1
, then we can use the following function syntax to write a string to a file:
<fileID>.write(<string to write>)
%10.5f or %d to format specifiers to take care of the numbers
Modules - Correct answer-Common Modules:
import matplotlib.pyplot as plt
import numpy as np
import math
Calling Functions - Correct answer-<function>(<arguments>)
ex: print( ), sqrt( ), etc
Dot Format for file I/O
A.<function>(<arguments>)
The name before the dot is an object of a particular type
©COPYRIGHT 2025, ALL RIGHTS RESERVED 2
Answers Graded A+
File I/O - Correct answer-<fileID> = open("<File Name>", "<designator>")
File I/O: what is the designator for? - Correct answer-Designator is either "r" for
reading or "w" for writing to a file
Part 1) Functions available after successfully opening a file - Correct answer-to
read a line from a file that is open for reading: readline( ).
*Syntax for readline( ) function:
<string variable> = <fileID>.readline()
This returns a string from where the file pointer is at the beginning of the call until
a newline character is found.
Part 2) Functions available after successfully opening a file - Correct answer-If we
successfully open a file for writing,
©COPYRIGHT 2025, ALL RIGHTS RESERVED 1
, then we can use the following function syntax to write a string to a file:
<fileID>.write(<string to write>)
%10.5f or %d to format specifiers to take care of the numbers
Modules - Correct answer-Common Modules:
import matplotlib.pyplot as plt
import numpy as np
import math
Calling Functions - Correct answer-<function>(<arguments>)
ex: print( ), sqrt( ), etc
Dot Format for file I/O
A.<function>(<arguments>)
The name before the dot is an object of a particular type
©COPYRIGHT 2025, ALL RIGHTS RESERVED 2