(Solved) : Objectives Demonstrate Basic Knowledge Python Writing Reading Csv Files Directions 1 Revie Q41427363 . . .

Objectives Demonstrate basic knowledge of Python and writing toand reading from CSV files.

Directions 1. Review the mpg python program introduced at thebeginning of this class to determine miles per gallon posted withthis Assignment on Canvas. 2. Review the code and determine how itworks. 3. Modify the program to allow the user to enter multipletrips (miles driven and gallons of gas used), calculating the mpgfor each trip. (Add a repetition structure) 4. If the user does notenter numeric values, the program must recover and allow the userto correct the value input. Implement a Python function to read anumeric value and allow the user to correct the value if it is notnumeric. The function should receive a string as a parameter thatcontains the prompt to display to the user. The program should notcrash due to an invalid value. 5. Modify the program to store thedata for each calculation, or trip, in a two-dimensional list.After each trip is added to the list, print out all elements of thelist. a. The list increases in size as you run it since you areappending all “calculation runs” to the list. b. For eachcalculation, add these values to the list: miles driven, gallons ofgas used, and calculated value of MPG. c. Stop there and make surethe repetition and list functionality are working correctly beforeproceeding. 6. Modify the program to save the data in the list to afile named trips.csv when the user chooses to exit the program. Themovie list program is a useful reference program for completingthis task. a. Verify the file is created correctly by opening thecsv file with a spreadsheet program like Excel and viewing thecontents. 7. Modify the program to ask the user if they would liketo read trips from a csv file before entering new trip data. a. Ifthey do, prompt the user for the filename. b. Open the file andread the contents into the list of trips. c. After reading thefile, the program should function as described above. d. Addexception handling to recover if the file does not opensuccessfully. 8. Your file should look like the screenshot below.9. You should add functions to write the list to a csv file, readthe list from a csv file, and to validate the user’s trip inputs asnumeric. Other functions may be added as desired. 10.Upload thePython file and the csv file your program created to GitHub forActivity 6. Sample csv file contents if 4 trips entered (format:miles, gallons, mpg) 100.0,10.0,10.0 300.0,3.0,100.0150.0,30.0,5.0

Rubric Python Program 5 Points 4-3 Points 0 – 2 PointsRepetition structure implemented and inputs validated 5 points Useris allowed to enter multiple trip data and only numeric values areaccepted (function implemented). User may correct inputs. Multipletrips not allowed, numeric values are not validated, or functionnot implemented. Functionality missing or incomplete.

Notepad

# display a title

print(“The Miles Per Gallon program”)

print()

# get input from the user

miles_driven= float(input(“Enter miles driven:tt”))

gallons_used = float(input(“Enter gallons of gas used:t”))

# calculate and round miles per gallon

mpg = miles_driven / gallons_used

mpg = round(mpg, 2)

# display the result

print()

print(“Miles Per Gallon:tt” + str(mpg))

print()

print(“Bye”)

Expert Answer


Answer to Objectives Demonstrate basic knowledge of Python and writing to and reading from CSV files. Directions 1. Review the mpg…