I keep getting the following error for this activity:

Oops, try again. trip_cost(‘Charlotte’, 4) raised an error: cannot concatenate ‘str’ and ‘NoneType’ objects

```
def hotel_cost(days):
return 140*days
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:
return cost - 50
elif days >=3:
return cost - 20
return cost
def trip_cost(days, city):
return hotel_cost(days) +plane_ride_cost(city) + rental_car_cost(days)
```

Here,

Try passing city as the first argument like this.

```
def trip_cost(city, days):
return plane_ride_cost(city) + hotel_cost(days) + rental_car_cost(days)
```

1 Like

awesome that fixed it but can you explain to me why the order of the arguments matters?

1 Like

Because Control Flow.

The way your arguments are arranged is the order in which they can be used and since I put `plane_ride_cost(city)`

first python knows that is the first argument called.

Its like defining a function that adds

```
def add(x, y):
return y + x
```

Do you think the code will run correctly?

how does that not affect the fact that days is being used twice?

Because the number of times an argument is used in a function has no limit.

But I would always have to call in order. So as soon as I call the second argument I can no longer call the first argument?

1 Like

Yes, Control Flow is a big part of functional programming.

If you don’t write your code in the right order; your debugging process will be a lot longer.

2 Likes

bocemb
May 27, 2016, 6:14am
10
Hi, I tried reversing the order

def trip_cost(days, city):
return hotel_cost(days) + rental_car_cost(days) + plane_ride_cost(city)

However when doing so I got a error reading "Oops, try again. trip_cost(‘Pittsburgh’, 5) raised an error: unsupported operand type(s) for -: ‘str’ and ‘int’ "

How does this error come about?

dave.n
May 27, 2016, 7:57am
11
Post your code now with the correct order so we can see what else is causing an error.

I just love u!

I was trying to make this work the whole week!!!

I REALLY thank you! You saved my day, dude!!!

2 Likes

Oops, try again. trip_cost(‘Los Angeles’, 2) raised an error: unsupported operand type(s) for -: ‘str’ and ‘int’

```
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 =cost- 50
elif days>=3:
cost =cost- 20
return cost
def trip_cost(days,city):
return plane_ride_cost(city)+rental_car_cost(days)+hotel_cost(days)
```

katpadi
September 26, 2016, 6:26am
18
Hi

I am getting the error “TypeError: cannot concatenate ‘str’ and ‘int’ objects”

Here is the code

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
else:
return ‘We don’t provide service for this Destination’
def rental_car_cost(days):
rent = 40 * days
if days >= 7:
rent = 40 * days - 50
return rent
elif days >=3 and days <=7:
rent = 40 * days - 20
return rent
else:
return rent
def trip_cost(city,days):
return plane_ride_cost(city) + hotel_cost(days) + + rental_car_cost(days)

the plane_ride_cost() function is returning the string not integer
how to rectify it.

1 Like

dave.n
September 26, 2016, 11:25am
19
Call your function with one of the cities as a parameter and it should return an integer. And the error is here,

It solved my problem too. But, why does it behave like that?

1 Like

dave.n
September 27, 2016, 5:09pm
21
like what the calling of the function or parameters?

Thanks to this thread I finally got past this section of the course. I’m still unsure in my understanding on how functions pass data in terms of the number of arguments/type and the variables used in the function and their order. Is there a more indepth lesson on this or an external site that provides more information with examples on this? Thanks