Question: In lab 1 2 we built a program that calculates the mean and median based on the data from a file. However, what if the
In lab we built a program that calculates the mean and median based on the data from a file. However,
what if the user types in the wrong file name? In this lab the goal is to refactor lab to handle a
FileNotFoundError
The user should enter the name of the file.
If the file exists, process it similar to lab
If it doesnt exist, inform the user and ask if they would like to enter a different file name
If the file was processed successfully, inform the user of such.
Additionally, keep track of the number of attempts the user tries to enter a file name. Include both successful
and unsuccessful attempts.C:IWINDOWS SYSTEMcmdexe
enter file name: abc
File not found. Try another file name? :
number of tries so far:
enter file name: xyz
File not found. Try another file name? :
number of tries so far:
enter file name: fruit.txt
File not found. Try another file name? :
number of tries so far:
enter file name: unknown
File not found. Try another file name? :
number of tries so far:
No file found. Exiting program.
program exited with code:
Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
