0

I have a question about python in VS Code. In IDE spyder I can define a function and test it in the terminal. For example:

def test(a):
    return a + 1

If I write in terminal test(4) it will return 5. How can I make this work in VS Code? The same example in VS Code returns this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'test' is not defined
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 2
    Does this answer your question? [How do I find/excute Python Interactive Mode in Visual Studio Code?](https://stackoverflow.com/questions/64730660/how-do-i-find-excute-python-interactive-mode-in-visual-studio-code) – mkrieger1 May 07 '22 at 16:53
  • VS-Code makes it super easy to run a Jupyter Notebook, personally I'd just start there~ – BeRT2me May 09 '22 at 04:40

1 Answers1

0

You have two ways to solve this problem:

1.creat a python file and run this file:

enter image description here

enter image description here

  1. Run code in terminal

enter image description here

MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13