I have tried to run a pretty simple code
x = input("What's x? ")
y = input("What's y? ")
z= int(x) int(y)
print (z)
But, when I try to run that code from the terminal writing "name_of_the_file.py", I find this error:
"The term "name_of_the_file.py" is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
If a right click on where you write the code, and then click on "run python file in terminal", it runs!
I am taking the CS50P, and I see that this should be possible because the teacher is able to do that. What am I doing wrong guys?
CodePudding user response:
try to follow these steps:
- Create a folder where you want your script to run
- Open the folder using VS Code: File -> Open Folder
- Create your script and save it in the folder
- Open a new terminal: Terminal -> New Terminal
- Type the command: python name_of_the_file.py
- If it doesn't work, try: py name_of_the_file.py
- If you are using a python 3 version, try: python3 name_of_the_file.py
My output:
CodePudding user response:
Do follow below steps
Open terminal in VS code
go to directory where you have .py file located using cd command
run command in terminal (eg. python3 file_name.py
Me@MyMacBook-Air string % python3 str_to_int.py
Hope this helps