Pull it together : A little adjustment that Worked!

#1

I was stuck at Taking a Vacation lesson. Initially, console was showing error message "can not concatenate str and int types"; But cost estimation was right.
I rushed through forums and got a solution to add a function "spending_money" in existing code. I ran the script and last error was resolved but cost estimation was wrong. Script wasn't calculating right costs for particular cities. Then I nullified the effect of spending_money cost by adding zero as multiplication factor.
And then, script run successfully.

``````def hotel_cost(night):
return 140*night

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 0

def spending_money(days):
days > 0
return 0 * days                                #Do not let spending money affect your trip cost

def rental_car_cost(days):
if days >= 7:
car_rent = (days*40) - 50
return car_rent
elif days >=3 and days <= 7:
car_rent = (days*40) - 20
return car_rent
else:
car_rent = days*40
return car_rent

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

print trip_cost('Tampa', 4)``````

#2

but you didn't have to have a spending_money function? spending_money should have been a parameter of trip_cost, and then you can just add it

#3

I've tried that sir. It wasn't helping. If I added spending_money with an explicit value, the calculation that script made is not expected, since answer would always deviated from the expected answer which is calculated by taking reference of city we choose. When I tried the suggestion, console was showing error message like the code is showing value xxx where expected value is yyy. This is where I got idea to nullify the spending_money without touching its very existence.
Before coming to this adjustment I went from the forum and found two links that made me to adjust the code as I did.

#4

can i see your code where you tried this?

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.