pythonfunctionvisual-studio-codejupyter-notebookpep

Why is my function not working in vscode when it works in jupyternote book?


I am new to python and have recently started to study it full-time. I have been using vscode to type out my code I would run the script and it would show my output in the terminal window.

However, I cannot get a lot of the functions I create to display an output in the terminal window. However, as a comparison check, I ran the same code in a Jupyter notebook and it worked perfectly fine. I also tried running this code on another laptop in vscode running it as a python file. But nothing has worked.

Here is the code running as a python file in vscode:

Running as a python file

Here is the code running in a jupyter notebook in vscode:

Running in a jupyter notebook

I apologise if I have been unclear. Do feel free to ask any questions to get a better understanding. I am a noob at this, so any help would be really encouraging. Thanks :)


Solution

  • Jupyter display in the console the value of the last line of code in a cell.

    In normal Python scripts this does not happen. If you want to see the output in the console you need to use the print() function or similar.

    so in your case:

    print(capitalize_letters("mcdonald"))
    

    or

    capitalized_word = capitalize_letters("mcdonald")
    print(capitalized_word)