I dont understand 3/7


#1

i cant do it, its so hard


#2

The example they give is exactly what you do,

if city == 'city_name':
return price
elif...


#3

As I posted earlier in this post the way they do this particular function is just plain bad.

I don't get why they have us write such bad code, one thing you should always remember in programming if you are writing the same thing over and over again reprogram it!

They should be doing this instead.

city_prices = {
    "Charlotte": 183,
    "Pittsburgh": 222,
    "Tampa": 220,
    "Los Angeles": 475
}

def hotel_cost(nights):
    return 140 * nights

def plane_ride_cost(city):
    return city_prices[city]

def rental_car_cost(days):
    car = 40 * days
    if days >= 7:
        car -= 50
    elif days >= 3:
        car -= 20
    return car

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

print(trip_cost(city='Charlotte', days=5, spending_money=1250))

And not this

def plane_ride_cost(city):
    if city == 'Charlotte':
        return 183
    elif city == 'Pittsburgh':
        return 222

#4

Um, isn't that Java?


#5

@goss34

Nope,

public class test {
    public static void main(String[] args){

    }

    private float cityPrices(String city){
        switch (city){
            case "Charlotte":
                return 183;
            case "Pittsburgh":
                return 222;
            case "Tampa":
                return 220;
            case "Los Angeles":
                return 475;
            default:
                return 0;
        }
    }

    private int hotelCost(int nights){
        return 140 * nights;
    }

}

That's a little bit of the java needed.


#6

here is what i used which worked using python only

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