Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This must be in Python! Write a function that accepts a filename as input argume

ID: 3703897 • Letter: T

Question

This must be in Python!

Write a function that accepts a filename as input argument and reads the file and saves each line of the file as an element in a list (without the new line (" ")character) and returns the list. Ask the user :

Each line of the file has comma separated values: For example

Then the function should return a list such as :

Should catch the exception if file not existed. Let the system decide to display the error message.

O_exc.py 1 def list fr om_file(file_name): # Your code goes here # 4 5 6 7 def main): file_name - input("Enter the input file name: ) # Your code goes here # 13 10 12 13 14 main

Explanation / Answer

def list_from_file(file_name): lst = [] try: with open(file_name, 'r') as f: for line in f: lst.append(line.strip()) except: lst = [] return lst def main(): file_name = input('Enter the input file name: ') print(list_from_file(file_name)) main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote