I'm stuck at pull it together!


#1

this is my code. And for the life of me, i can't figure out what the issue is.
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):
total =( days*40)
if days >= 7:
return total-50
elif days >= 3 and days < 7:
return total-20
else:
return total
def trip_cost(days,city):
return rental_car_cost(days)+hotel_cost(days)+plane_ride_cost(city)

the error keeps changing and one of the lot are : Oops, try again. trip_cost('Los Angeles', 8) raised an error: unsupported operand type(s) for -: 'str' and 'int'


#2

I have tried other people's codes from other 'pull it together' posts. But nothing is working out. I've been at it since morning and my mind is fried. Halp!


#3

ok fine i have figured it out:
the arguments in trip_cost should be (city, days) and I wrote it the other way. Can someone explain me why does it make a difference?
Thanks!


#4

The variable nights is not defined outside of this function. However, as you've seen, we can pass days to hotel_cost() from within trip_cost() since it is defined locally in that function.

def trip_cost(days, city):
    return ... + hotel_cost(days) + ...

def hotel_cost(nights):
    # nights is a local copy of days

#5

Hi mtf!

I meant, I wrote (city, day) as the argument and not (days, city) in that order. So I guess, since they have specifically mentioned the arguments has to be in (days, city) order; it worked that way. Otherwise it threw me an error when I wrote (city, days)....other than that my code was correct.
Thanks for replying :slightly_smiling:


#6

For named parameters (also known as formal parameters) the order in which they appear in the parameter list is of no concern. They may be written in any order.

It is important that we use consistency in our spelling, though. If your original code did in fact use day then that would cause problems.

Glad you got this figured out. Happy coding!


#7

OMG. wait.
so from my code, def_trip (days, city) worked. But before changing it from def_trip(city, days) it threw an error. That was the only thing i changed and the code worked.
so you're saying the order of the arguments are irrelevant? :frowning:


#8

What kind of error? An SCT error or a compiler error (in red in the console)?