Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

look at the TODO comments add in the requested functionality do not modify existing code only add code where there are the TODO comments -------------------

look at the TODO comments

add in the requested functionality do not modify existing code only add code where there are the TODO comments

-------------------

class Car: def __init__(self,*x): if len(x)!=3: raise Exception("NOT CREATED CORRECTLY") self.mpg=x[0] self.tankCapacity = x[1] self.currGas = x[2]

def travelMiles(self, miles): possDist = self.mpg*self.currGas if possDist < miles: print("YOU BROKE DOWN...OUT OF GAS") self.currGas = 0 else: self.currGas -= miles / self.mpg print("You traveled {} miles".format(miles))

# TODO: Add in refuel car function, that fills the tank to capacity

def __str__(self): return "Car ({}) {}/{} gallons".format(self.mpg,self.currGas,self.tankCapacity)

def main(): pass # TODO ADD CODE HERE # Ask the user for the tank size of their car and its mpg rating, create an instance of that car and make sure the tank is full (DO NOT USE REFUEL FUNCTION, initialize as full) # Travel 5 miles # Print out the car in the format: Car () currentfuel/capacity example: "Car (30) 7/18 gallons" # Refuel Tank # Travel 1000 miles # Print out the car in the format: Car () currentfuel/capacity example: "Car (30) 7/18 gallons"

if __name__=="__main__": main()

------------------------

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

ISBN: 0805302441, 978-0805302448

More Books

Students also viewed these Databases questions