Glitch? 4/7 Taking a Vacation


#1

this is my code:


def hotel_cost(nights):
return 140 * nights

def plane_ride_cost(city):
if city == "Charlotte":
return 183
if city == "Tampa":
return 220
if city == "Pittsburgh":
return 222
if city == "Los Angeles":
return 475

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


I need help with this, tell me if its a glitch please!


#2
  1. you need to remove the else: and the rent after it.

  2. replace the rent after the if/elif with return and add = after the -

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

#3

thx for trying, but its still not working. I think its just glitched but the code wont work :frowning:


#4

Well, there is always a easier way about things, this is the code I am using. The bunch of if/else statements they have you create is error prone as all hell as you will come to find out.

Remember "Flat is better than nested!".

do

import this

Now this is my code, I get rid of the nest garbage and go with something that is more elegant. Other than that the rest is the same.

def hotel_cost(nights):
    return 140 * nights

def plane_ride_cost(city):
    return city_prices[city]

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

EDIT:

Forgot you need this too

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

#5

Here's what I used and it worked:

def rental_car_cost(days):

rent = 40 * days

if days >= 7:
    return rent - 50
elif days >= 3:
    return rent - 20

return rent

#6

thx you guys. i got the prob fized thou. it turns out it was just a glitch in my computer. Thx you guys for trying to help thou :sunny: :ghost: :smiley:


#7

When I put in -= the console window says its invalid syntax. I'm really struggling with this one and I'm not sure if its a glitch or not.


#8

the one that im working on turned out to be just a glitch. I'd give you my code to help but it wont lemme go back to that lesson. Try fatkungfu's hint and see if that helps.