Assignment 7 - Vinniethatguy/UMKCCS101Labs GitHub Wiki
Fuel EconomyIn this lab we’ll write a program to read through a file containing information about fuel economy and output the results to a file above a threshold that the user gives. If the user wants to see all vehicles with a combined mpg greater than 50, then yourprogram will output that information to the file of their choosing. The information is tab-delimited. When you read a line from the file, the values are separated by the tab character \t. There are many ways to split this string data.Vehicle file org.
Your program will need to ask the user for a minimum fuel economy, and be able to handle non float data being entered. It should continually ask for a correct value. It should also make sure they don’t enter a value less than or equal to zero or greater than 100. The program will ask for an input file and should loop until the user gives a valid file that can be opened. It should also CS101LPage 2of 3ask for an output file. While a FileNotFoundError won’t be thrown trying to open a file in write mode, it can generate an IOError.
This assignment was very difficult, but I start out with an variable that checks for illegal characters in a text file name. Then its followed by a while loop, asking for the minimum mpg, and a if/elif and else statements. We are only looking for the 0,1,2,-3 index values of out list in the text file. I used with open, because its a lot easier to run than the open and close functions.