Python: Print Function Ignored - "Taking a Vacation": "Plan Your Trip"


#1

Hello,
I have been learning Python, and for some reason, I have encountered a strange error where the console is not reading my print function. I set up the code so that I would receive a printed value depending on the number that was inputted into the console. However, the print value would be skipped over.

> print "The hotel costs $140 per night"
> def hotel_cost(nights):
>     return 140 * nights
> def plane_ride_cost(city):
>     if city == 1:
>         print "The cost to travel to Charlotte is 183"
>         return 183
>     elif city == 2:
>         print 220
>         return 220
>     elif city == 3:
>         print 222
>         return 222
>     elif city == 4:
>         print 475
>         return 475
>     else:
>         print "Follow the directions!"
> city = input("Enter 1 for 'Charlotte', 2 for 'Tampa', 3 for 'Pittsburgh', or 4 for 'Los Angeles'")

Here is a clarifying image:

The printed value should be 183, yet it never shows up. Any suggestions?
Thanks for the help.

python
.
indent preformatted text by 4 spaces


#2

@systemsurfer85527,
You have defined the function's

You still have to call such a function....

thus after your

city= input("......")
print plane_ride_cost(city);

== Some thoughts ===============================

def plane_ride_cost(city):
    if city == 1 or city == "Charlotte":
        print "The cost to travel to Charlotte is 183"
        return 183
    elif city == 2:
        print 220
        return 220
    elif city == 3:
        print 222
        return 222
    elif city == 4:
        print 475
        return 475
    else:
        print "Follow the directions!"

def translate_city_input(x):
    return {
    "1":'Charlotte',
    "2":['Tampa',220],
    "3":'Pittsburgh',
    "4":'Los Angeles'
    }.get(x, "unknow")

city = "1"
print plane_ride_cost(translate_city_input(city))
city = "2"
print("{0} costs {1}".format(
    translate_city_input(city)[0],translate_city_input(city)[1]))

[output]

The cost to travel to Charlotte is 183
183
Tampa costs 220