Question: Write a function named ask _ file _ name that repeatedly prompts the user for a file name until the user types the name of
Write a function named askfilename that repeatedly prompts the user for a file name until the user types the name of a file that exists on the system. Once you get a good file name, return that file name as a String. Here is a sample dialogue from one call to your function, assuming that the file good.txt does exist and the others do not:
Type a file name: bad.txt
Type a file name: nothere.txt
Type a file name: good.txt
So this is my code:
import os
def askfilename:
while True:
filename inputType a file name:
try:
f openfilename,"r
return filename
except:
pass
printaskfilename
But it says there is an error: problem return type error: expected string, but no value was returned from line in Step by Step. How do I fix this?
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
