6/7 help!


#1

my code wont work at all i have been trying for weeks can someone help please?

def hotel_cost(nights):
    hotel_cost = 140*nights
    return hotel_cost
cities = {
    "Charlotte": 183,
    "Tampa": 220,
    "Pittsurgh": 222,
    "Los Angeles": 475
    }
def plane_ride_cost(city):
    try:
        return cities[city]
    except:
        print("Not a valid destination.")
def rental_car_cost(days):
    if days < 3:
        return 40*days
    elif days >= 3 and days < 7:
        return 40*days - 20
    else:
        return 40*days - 50
def trip_cost(city,days,spending_money):
    return plane_ride_cost(city) + 2*rental_car_cost(days) + spending_money

FYI here is the error message:

Oops, try again.
plane_ride_cost('Pittsburgh') returned None instead of the correct value 222

#2

you misspelled Pittsburgh.


#3

thanks it still doesnt work though here is the new code:

def hotel_cost(nights):
    hotel_cost = 140*nights
    return hotel_cost
cities = {
    "Charlotte": 183,
    "Tampa": 220,
    "Pittsburgh": 222,
    "Los Angeles": 475
    }
def plane_ride_cost(city):
    try:
        return cities[city]
    except:
        print("Not a valid destination.")
def rental_car_cost(days):
    if days < 3:
        return 40*days
    elif days >= 3 and days < 7:
        return 40*days - 20
    else:
        return 40*days - 50
def trip_cost(city,days,spending_money):
    return plane_ride_cost(city) + 2*rental_car_cost(days) + spending_money

and the error:

Oops, try again.
trip_cost('Tampa', 2, 0) returned 380 instead of the correct value 580

#4

i have indents in it they just didint come up for some reason idk why though!


#5

you got to put your code inbetween those triple dashes to make it appear as in the lesson. So put it where you put your error in your last reply and it will appear as it should.


#6

thanks i edited the post but the code doesnt work idk why


#7

and now whenever i hit submit code i get different errors like these:
Oops, try again.
trip_cost('Charlotte', 5, 0) returned 543 instead of the correct value 1063

Oops, try again.
trip_cost('Pittsburgh', 5, 0) returned 582 instead of the correct value 1102

Oops, try again.
trip_cost('Tampa', 5, 0) returned 580 instead of the correct value 1100

Oops, try again.
trip_cost('Los Angeles', 1, 0) returned 555 instead of the correct value 655


#8

why do you multiply rental_car_cost by two? no need for this. And you never call hotel_cost in the trip_cost function, you do have to pay for the hotel, if problems persist post an updated version of your code


#9

i figured it out thanks to both of you!!!!!!!!!!!!!!


#10

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