Okay, I’m really new with python and in my class the prof assigned a homework where we fix codes without wing. I’m really confused because the prompt asks us to ‘open a terminal window by clicking on the icon in the task bar that looks like a terminal screen. After it opens, it will display a prompt. Type the commands:
cd Desktop/cs141/11execution
python hello.py
So I understand what it is asking me to do and I think I opened the terminal window… but it gives me a syntax error. Can someone explain to me how to actually use python (how to open files without using wing.). I’m sorry if this sounds dumb but I’m extremely confused because i can’t even open the file to get working on it.
I opened the terminal window and I typed in the command that the homework told me to do and it gave me this:
cd Desktop/cs141/11execution
File "<stdin>", line 1
cd Desktop/cs141/11execution
SyntaxError: invalid token
Because your actual homework assignment is to run and debug code without the help of an IDE, I figure I can at least give you details about the process leading up to that which is troubling you… And I can edit this answer to suit your updates.
When you open a terminal, you should see a command prompt waiting for input. This is a shell. Which shell you are in by default is system-dependent, but lets assume its “bash”. Its probably bash if you see the prompt ending in “$”
When you are in a bash shell, you can issue commands. Python scripts start out by telling the system what type of interpreter it would need to be understood. Your script most likely starts with something like
#!/usr/bin/env python, telling the system that the following text should be run using python.Make sure you are actually in the command prompt and NOT a python interpreter
So once you have a terminal open, you first wanted to change to the directory where your python script is located.
cd /path/to/locationtells bash to change the current working directory. You would now be located in the spot where your python script exists.When you run
python myscript.py, you are explicitly telling python to run this script, regardless of what is at the top of the script with the#!.... At this point, your script should execute and the output would be related to the script.In your example output, you have most likely entered a python interpreter, which is possibly by simply typing
python. You can verify this if you end up seeing it waiting for input with>>>. At this point you have done something wrong.cdis not a valid python command. It is a shell command.Update
You are now obviously in windows, so as I mentioned in my main comment… Open the command prompt by going to Start Menu -> Run -> Type ‘cmd’ -> Hit Enter. Now continue following your directions.