I just started a python bootcamp and am using Microsoft Visual Studio Code (latest version with Python 3.10.5) but have a couple of questions. (apologies for the long post)
I have the following code:
def weather_condition(temperature):
if temperature > 7:
return "Warm"
else:
return "Cold"
input("What temperature: ")
To my knowledge there are three options to run the code
- Right mouse click and 'run python file in terminal
- Select lines and press SHIFT + ENTER
- RUN (with or without debugging)
However even though the script is the same, each choice shows a complete different result in the terminal.
- If I choose to run the python file, it shows the following error in the terminal:
>>> & C:/Users/..../AppData/Local/Microsoft/WindowsApps/python3.10.exe d:/..../_SCRIPTING_/Python/Python001/user_input2.py
File "<stdin>", line 1
& C:/Users/fine/AppData/Local/Microsoft/WindowsApps/python3.10.exe d:/..../_SCRIPTING_/Python/Python001/user_input2.py
^
SyntaxError: invalid syntax
- If I choose select lines (same lines used as #1),
it runs the script but it displays the entire script run process in the terminal (which doesnt happen on the teacher's visual code:
mine:
>>> def weather_condition(temperature):
... if temperature > 7:
... return "Warm"
... else:
... return "Cold"
...
>>> input("What temperature: ")
What temperature:
teachers: teacher's screen
- And last but not least is the Run script (with or without debug).
Which opens a completely new Python 'debug' terminal. Here the script runs normally (it seems) and looks more like the teacher's version although his screen doesn't show 'debug' or the small toolbar
anywhere in his visual code.
A. So what is the difference between each of the choices?
B. Which of the 3 should I be using?
C. Why does the first option give an error even though the script is written correctly?