Trying to add some things one my own but code dosn't work


#1



https://www.codecademy.com/courses/python-beginner-P5YtY/1/6?curriculum_id=4f89dab3d788890003000096

Traceback (most recent call last):
File "python", line 25, in
File "python", line 20, in trip_cost
File "python", line 15, in rental_car_cost
TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'

Actually I passed the exercice but what I'm trying to do is to make the program more interactive with the user and takes an input but the problem is that after it takes the inputs I get an error message :confused: please help..

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 plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(days) + spending_money

city =raw_input("Where are you planning to go ? Which city?")
days= raw_input ("How many days are you planning to stay in "+city+"?")
spending_money=raw_input("How much money are you planning to spend on extra things like souvenirs?")
print trip_cost(city, days, spending_money)

#2

raw_input will give you a unicode datatype.

in case of city, you need a string, so i suggest we just cast it to a string:

city=str(raw_input("Where are you planning to go ? Which city?"))

in case of days and spending money you need a integer:

days=int(raw_input ("How many days are you planning to stay in "+city+"?"))

#3

Thanks for the reply but I actually just tried it and look what I got :
Traceback (most recent call last):
File "python", line 25, in
File "python", line 20, in trip_cost
TypeError: unsupported operand type(s) for +: 'int' and 'unicode'


#4

@chipace76220 i modified your code according to stetim94 suggestion and for me it worked out

city = str(raw_input("Where are you planning to go ? Which city?"))
days = int(raw_input ("How many days are you planning to stay in "+city+"?"))
spending_money = int(raw_input("How much money are you planning to spend on extra things like souvenirs?"))

Task doesn't pass due to value error, however the code is working


#5

Thanks it worked I forgot to put int for the spending_money


#6

i left some thinking for you to do, i am not going to spoil all the fun. Good you made it work