logo CodeStepByStep logo

print_entire_file2

Language/Type: Python file input

In a previous problem, you are asked to write a function named print_entire_file that prompts the user for a file name and printed that file's contents to the console. Modify your code from that problem into a new function named print_entire_file2 that will repeatedly prompt until the user types the name of a file that exists on the system. If you like, you can call the function get_file_name from Self-Check 6.20 (without rewriting or pasting it here) to help you solve this problem. For example, if the file example.txt contains the following input data:

hello  how    are you
1 2 3 4

I am fine

Then the following would be an example dialogue of your function:

Type a file name: bad.txt
Type a file name: not_here.txt
Type a file name: alsobad.txt
Type a file name: example.txt
hello  how    are you
1 2 3 4

I am fine
Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.