1

I am currently learning Python and have come across a very strange problem (to me at least). When I type this code:

def search4vowels(word):
    """Display any vowels found in a supplied word."""
    vowels = set('aeiou')
    found = vowels.intersection(set(word))
    return bool(found)

in an IDLE edit window and run it using IDLE, it all works fine and I need to type my function in at the prompt in order for it to start.

However, when I write the same code in Visual Studio Code and run it using the Run Python file in Terminal option all I get is:

IDE screenshot

I have also tried the Code Runner extension and that gives me a blank output page and no way to type in the function.

For example: search4vowels('galaxy')

And the output that I expect should be: True (Because a vowel would be present in the word, therefore True)

However, nothing happens.

1 Answer 1

5

You are defining function search4vowels(), but Visual Studio Code doesn't know how to run it.

Try adding this in your code:

def search4vowels(word):
    """Display any vowels found in a supplied word."""
    vowels = set('aeiou')
    found = vowels.intersection(set(word))
    return bool(found)

# This tells your code to run the function search4vowels():
if __name__ == '__main__':
    print(search4vowels('your word'))

Here is the manual page about the word "__main__".

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this fixed it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.