Question: I am coding a program that opens two files that have data of car specs. ( year, model, cylinders, trans, mpg, and etc.) The user

I am coding a program that opens two files that have data of car specs. ( year, model, cylinders, trans, mpg, and etc.) The user is then supposed to enter a number for mpg that will return a car with those within those mpg parameters.

When I run my progam nothing comes up after entering the 3 required text

code is:

def open_file(prompt, mode='r'): while True: try: filename = input(prompt) file = open(filename, mode) return file except FileNotFoundError: print('Could not open file.', filename) except IOError: print("There is an II Error.*", filename)

def get_min_mpg(): while True: try: mpg= float(input("Enter the minimum mpg ==? ")) if mpg 100: print('Fuel economy must be less than 100.') else: return mpg except: ValueError print("You must enter a number for the fuel ecoonomy.")

mpg = get_min_mpg()

print() file = open_file("Enter the name of te input vehilce file ==> ") file.readline()

print() output_file = open_file("Enter the name of the file to output to ==> ", 'w') for line in file: values = line.split ("\t") try: combined = float(values[7]) if combined>= mpg: output_str = "(:10.3f)".format(values[0], values[1], values[2], combined)

except ValueError: print(" Could not convert value [] for vehicle [] [] [] ".format(values[7], values[0],values[1], values[2])) file.close() output_file.close()

I am coding a program that opens two files that have data

week py-Wkcumkc eduioc-usershomelccg2rc Desktop Projetweek0py (36.5 File Edit Format Run Options Window Helo det open fsle(ronp node-"' while Tzue EEY filename-input (prompt Eile open ilenare, mode) return file print 'Could not open tile.'. tiienana) excep IOEror: print ("There 18 an 11 Error. ", filename} 1le True: agoF r1aat (input?"Enter the minimum mpg ;? ")) prin('Fuel ecenons given mast te qreate than .' elif n100 print('Fuel economy ust be 1eaa than 100..) excegti Valuelrror print("You must enter a nunber for the ruel ecoonony." print) file-openfile("Ent r he name of te input vehilce file--> ile.readiine - print () urput iieopenfiie ("Enzex the nam of che tile to ourput O".' tor line in f11: values -line.split car bined-float(valusat71) output-st-- .I ; 10.3t)".tornat (values [oj, values[1], values 12], combine excepz ValueIrro: print(" Could not convert alue 1 tor vehicle II L ".tormat (valueLvaluestol,valuesaluesI2]1 tile.loae ) uEPutiie.cioaeD 46 Cel:0 610 PM 012/2010

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!