Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Mo Reese
Mo Reese
11,868 Points

What am I missing? Debug

I'm practicing my coding in Python, and while I'm slowly building up to a more elaborate script-I don't want to go further until i figure out what I'm missing so far. It works right up until it's supposed to give a result.

My Code:

HOTEL_CHARGE = 140
CAR_RENTAL = 40


def hotel_cost(nights):
    return (HOTEL_CHARGE * nights)

def plane_ride_cost(city):
    if city.lower() == "charlotte" or "c":
        return 183
    elif city == "tampa" or "t":
        return 220
    elif city == "pittsburgh" or "p":
        return 222
    elif city == "los angeles" or "l":
        return 475

def rental_car_cost(days):
    if days >= 7:
        return (CAR_RENTAL * days) - 50
    elif days >= 3:
        return (CAR_RENTAL * days) - 20
    else:
        return (CAR_RENTAL * days)
def trip_cost(city,days,spending_money):
    return (rental_car_cost(days) + hotel_cost(days - 1) + plane_ride_cost(city))

name = input("What is your name? ")
nights = input("Ok {}, How many nights are you staying? ".format(name))
nights = int(nights)
city = input("What city would you like to travel to, {}? ".format(name))
days = input("How many days are you renting a vehicle, {}? ".format(name))
days = int(days)
spending_money = input("How much money are you bringing to spend? ")

print (trip_cost)

All I get for an answer is:

<function trip_cost at 0x7f8106eaeae8>

I'm just not seeing what it is that I'm doing wrong. I'd appreciate the help and a fresh pair of eyes, thanks!

2 Answers

You need to include city[0].lower() on both sides of and. You are also missing parentheses on lower after the first one.

def plane_ride_cost(city):
    if city[0].lower() >= "s" and city[0].lower() < "z":
        return 183
    elif city[0].lower() >= "m" and city[0].lower() < "s":
        return 220
    elif city[0].lower() >= "g" and city[0].lower() < "m":
        return 222
    elif city[0].lower() >= "a" and city[0].lower() < "g":
        return 475
Mo Reese
Mo Reese
11,868 Points

And that is why you're the pro. I appreciate all of the help!

You aren't passing any arguments to your functions. Using the variable names you prompted for you'd have:

print (hotel_cost(nights))
print (plane_ride_cost(city))
print (rental_car_cost(days))
Mo Reese
Mo Reese
11,868 Points

Sigh... such a rookie mistake (face palm)... thank you for your help!

If you would be so kind... I did some more tinkering and now I'm hung up on trying to make the input for the city less specific. My intention is to do that by just using the first letter of whatever city is input-and so...

def plane_ride_cost(city):
    if city[0].lower() >= "s" and < "z":
        return 183
    elif city[0].lower >= "m" and < "s":
        return 220
    elif city[0].lower >= "g" and < "m":
        return 222
    elif city[0].lower >= "a" and < "g":
        return 475

after a few attempts I'm pretty much getting the same error message.

treehouse:~/workspace$ python tripplanner.py                                                                                                   
  File "tripplanner.py", line 9                                                                                                                
    if city[0].lower() >= "s" and < "z":                                                                                                       
                                  ^                                                                                                            
SyntaxError: invalid syntax

I thought this was how to alphabetize...