Don't know what's wrong..
Please help !!
None is the only instance of the class NoneType, so that's the value that you're dealing with.
(just like 5 is an instance of int)
So somewhere you try to do addition with None:
5 + None
Doesn't make sense, so you get an error message.
None represents lack of value, for example if a function doesn't return anything explicitly, it will return None
You've got a line number for the crash so you can tell which addition this is about. Just look at where it's coming from. You can add print statements in your code to follow along in how your code executes to see how it obtains the value None
Sorry, I don't get you.. Can you just do it for meh completely ?
From the instructions for the 'rental_car_cost' function: (
if) you rent the car for 7 or more days, you get $50 off your total. Alternatively (
elif), if you rent the car for 3 or more days, you get $20 off your total. Can't have two
if blocks in a row,
So, your code should be:
def rental_car_cost(days): cost = 40 * days if days >= 7: cost -= 50 elif days >= 3: cost -= 20 return cost
Try with removing
return cost in
But that has got to do nothing ..
Error is on line 25 and 27 !
You get info that something is wrong in those lines, but functions in those lines takes data from another functions. Those functions may work, but they can also return data, which don't "fit" to calculations made for e.g. in
def trip_cost. It's just my theory.
Did you remove that
return cost ?
Here's what worked for me:
def hotel_cost(nights): return 140 * nights def plane_ride_cost(city): if city == "Charlotte": return 183 elif city == "Tampa": return 220 elif city == "Pittsburgh": return 222 elif city == "Los Angeles": return 475 def rental_car_cost(days): cost = 40 * days if days >= 7: cost -= 50 elif days >= 3: cost -= 20 return cost def trip_cost(city, days, spending_money): return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money print trip_cost("Los Angeles", 5, 600)
You can try re-typing it, 'cause i got the same error when the editor bugged out and didn't format the
return part of trip_cost correctly.
Whoa.. Thank you so much !!
Also, if you’re having trouble with code that you think is correct be sure to try it out in
Fine.. Thank you so much !!
The print statement in the end has to be in the same indentation as the methods starting with def. Your current code doesn't work because you have the print statement as part of the trip_cost.