Search code examples
pythonbashfunctionreturn

Why is VSCode Python not outputting function returns to the terminal?


I'm fairly new to python and just started trying out VSCode. However, I created a function that is supposed to return a value, however when I run the program, nothing is outputting to the terminal. The programing I'm doing is part of a codecademy course. Here's the code;

destinations = ["Paris, France", "Shanghai, China", "Los Angeles, USA", "São Paulo, Brazil", "Cairo, Egypt"]
test_traveler = ['Erin Wilkes', 'Shanghai, China', ['historical site', 'art']]

def get_destination_index(destination):
    destination_index = destinations.index(destination)
    return destination_index

get_destination_index("Los Angeles, USA")

When I click run, all I get is this:

PS D:\Project\Location> & C:/Location/of/python3.11.exe/on/my/computer d:/location/of/script.py

I expected for the index of "Los Angeles, USA" in the list destinations to be outputted to the terminal. Any ideas?


Solution

  • I noticed the mistake in the code - you haven't wrote print() before calling the function. Here is the corrected code:

    destinations = ["Paris, France", "Shanghai, China", "Los Angeles, USA",
                    "São Paulo, Brazil", "Cairo, Egypt"]
    test_traveler = ['Erin Wilkes', 'Shanghai, China', ['historical site', 'art']]
    
    def get_destination_index(destination):
        destinations_index = destinations.index(destination)
        return destinations_index
    
    print(get_destination_index("Los Angeles, USA"))