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

TA Initials (20 Points) Implement the class Car with the following properties. A

ID: 3726737 • Letter: T

Question

TA Initials (20 Points) Implement the class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency should be specified upon instantiation, and the initial fuel level should be zero. Supply a method called drive that simulates driving the car for a certain distance, which reduces the fuel level in the gas tank. If the car is unable to drive the specified distance, this method should return False. Otherwise, drive should return True. Additionally, supply a method called get-gas.level to return the current fuel level and a method called add gas to add fuel back to the tank. An example of these methods in use is as follows: hybrid-car = Car(50) # 50 miles per gallon hybrid-car, add-gas (20) # Add 20 gallons of fuel if hybrid-car, drive(100): # Drive 100 miles print hybrid-car.get-gas-level() # Display remaining fuel else: print "Not enough gas!"

Explanation / Answer

Here is your python program -

numberofGallons=0 #initially
distance_to_travel=0
per_mile_gllons_required=0
ans=0
def gallons():
numberofGallons=eval(raw_input("Enter number of available gallons "))
return numberofGallons
  
def distance():  
distance_to_travel=eval(raw_input("Enter distance to travel "))
return distance_to_travel
  
def gallonsPerMile():
per_mile_gllons_required=eval(raw_input("Enter required nummber of gallons to travel one mile "))
return per_mile_gllons_required
def Add_fuel(totalG,totalC):
extraFuel=eval(raw_input("Add some gallons to the fuel "))
if(totalC>totalG + extraFuel):
print "Still you have to add more fuel to travel "
return False
else :
print "Now you can travel "
return True
def check():
totalG=gallons()
totalC=distance()*gallonsPerMile()
if(totalG>=totalC):
return True
else:
print "Gallons are required to add "
s=Add_fuel(totalG,totalC)
return s
  
Status=check()
print " Result for travel is "
print Status