So the file is called 'data.txt'. I need to write a program that prompts the user for input to see if it matches 'data.txt'. So for example, if i enter 'data', it will output:
Enter name of file:
data
File data not found.
so far, when i input 'data', my code:
# Define your functions here
if __name__ == '__main__':
file_name = "data.txt"
# Prompt the user for the name of the file and try opening it for reading
user_input = ''
while user_input in ['data.txt']:
try:
user_input = input('Enter name of file:')
my_file = open('data.txt')
lines = my_file.read()
# Use try-except to catch an error if the file does not exist
except:
print('File data not found.')
# Complete main section of code to read the file, compute the average weight and height, etc.
However, this displays (Your program produced no output).
Any tips on how to debug my code? Or what I need to fix?