Repository navigation
Assignment 7 Wiki
In 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 your program 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.
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 ask for an output file. While a FileNotFoundError won’t be thrown trying to open a file in write mode, it can generate an IOError.
When writing out to the output file, you should output the Year, Make and Model left justified by 40 spaces and the mpg right justified by 10 spaces.
Your program should also be able to handle an incorrect combinedmpg column as in vehicles2.txt. When a bad value that can’t be converted is encountered, you should warn the user and give the year, make and model that had the error.
For the program I started with def functions. Then I added print statements to each function. When coding I had to make sure the program could correctly accept the input file. Once it accepted the input, I had to make sure it could also make an output file that would work.
The screenshot shows the program asking for the user to input minimum mpg. The screenshot shows the user inputting a word instead of a number, and if the user input a number then the program does not accept it. The number must be greater than 0 and less than 100. Once the user inputs a number between that range, it will then ask the user to input the vehicle file. If the file is invalid then it will tell the user that could not open. Once the input file is valid then it will ask the name of the output file. If the output name file is invalid , then it will give you a IO error. Once it is valid then it will tell you what data it can not convert. Then you can open the output file that it created.