Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.
#!/usr/bin/python class TripCost: def __init__(self, miles_per_gallon, distance, price_per_gallon): self.miles_per_gallon = miles_per_gallon self.distance = distance self.price_per_gallon = price_per_gallon #self always has to explicityly called when using class level functions def Mileageprice_per_gallon(self): return (self.price_per_gallon * self.distance) def Roundtrip(self): return(self.distance * 2) #Creating a new object called trip with a car that has 22 mpg 13.6 mile drive and 3.27 for gas trip1 = TripCost(22, 13.5, 3.27) mpg =trip1.Mileageprice_per_gallon() print "The cost of the price per gallon and distance will be : " print mpg roundTrip = trip1.Roundtrip() print "The round trip will be" print roundTrip x_mpg = raw_input('How many miles per gallon does your vehicle give you?') print 'Your vehicle gives you ' + x_mpg x_distance = raw_input('How Far is your one way commute? ') print 'Your one way commute is ' + x_distance x_price_per_gallon = raw_input('What is the cost of fuel per gallon?') print 'The cost of fuel is ' + x_price_per_gallon #Convert all string input to integers i_mpg = int(x_mpg) print i_mpg i_distance = float(x_distance) print i_distance mult = (i_distance * i_mpg) print mult i_price_per_gallon = float(x_price_per_gallon) print i_price_per_gallon trip2 = TripCost(i_mpg, i_distance, i_price_per_gallon) mpg2 = trip2.Mileageprice_per_gallon() print mpg2
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.