Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Students will be able to: Content: Explain the purpose of write 0 functions Explain the difference between writing and appending to a file Process: Write
Students will be able to:
Content:
Explain the purpose of write functions
Explain the difference between writing and appending to a file
Process:
Write code that opens, writes to and closes a file
Prior Knowledge
Python concepts from Activities
Enter and execute the following program:
def main :
lastName input Enter last name:
firstName input Enter first name:
studentID input Bnter ID:
infile hopen stadentinfotxta
inFile.write Name: firstName lastName
inFil write
StadentID: studentID
inFile. write
infile. close
printDone Data is saved in file: studentInfo.txt
main
What output appears on the screen?
b What does the program do
c Locate the file studentInfo.txt on your computer. The file is stored in the same folder as the program. What is stored in the file?
d Change the argument to in the call to the open function. What is the purpose of the in the following line of code?
infile open studentInfo txtw
e Did you create the file: studentInfo.txt separately from the program code?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started