Question
python3 (1) a) Using a simple text editor (for example, the IDLE editor, TextEdit, Notepad), create a plain text (.txt) file of whatever you like
python3 (1) a) Using a simple text editor (for example, the IDLE editor, TextEdit, Notepad), create a plain text (.txt) file of whatever you like (e.g., favorite books, movies, important dates). The file should have at least two lines of text; it may be as long as you like (though you should test using a short file to start). Save the file. Examples:
Project9.txt or
DaysOfWk.txt. Then write a Python function, check_file, with one parameter, fname, the name of a file. check_file should open file fname, and print the contents of the file line by line, just as it appears in the file. None value is returned. The print function end=' ' optional argument may be useful. For example, for a text file that lists the days of the week:
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
>>> check_file('DaysOfWk.txt') Monday Tuesday Wednesday Thursday Friday Saturday Sunday
(b)Write a Python function, fbkup, with one parameter, fname, the name of a text ('DaysOfWk.txt') file i.e. fbkup(fname). fbkup will create a backup for file fname, with the name DaysOfWK-bkup.txt. Another example, the backup file for file best-movies.txt should have the name best-movies-bkup.txt. fbkup should return the name of the new backup file. (See hint below) After creating the backup file, check your results. Import function check_file from Project_WK9_OptionalA.py. Call function check_file to print the file you created. Then call fbkup to backup that file.
(c)Finally, call check_file to print the backup file. For example,
check_file('DaysOfWk.txt') mybackupf = fbkup('DaysOfWk.txt') #'daysofwk-bkup.txt' check_file(mybackupf)
The result of both calls to check_file should look the same.
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