small mistakes. A computer running Python code is not smart enough to do that. Whenever you write code, you’ll make mistakes. When you run a code cell that has errors, Python will sometimes produce error messages to tell you what you did wrong. Errors are okay; even experienced programmers make many errors. When you make an error, you just have to find the source of the problem, fix it, and move on. We have made an error in the next cell. Run it and see what happens. : print ( "This line is missing something." ) This line is missing something. : print ( "This line is missing something." ) This line is missing something. Note: In the toolbar, there is the option to click Cell > Run All , which will run all the code cells in this notebook in order. However, the notebook stops running code cells if it hits an error, like the one in the cell above. You should see something like this (minus our annotations): The last line of the error output attempts to tell you what went wrong. The syntax of a language is its structure, and this SyntaxError tells you that you have created an illegal structure. ” EOF ” means ”end of file,” so the message is saying Python expected you to write something more (in this case, a right parenthesis) before finishing the cell. There’s a lot of terminology in programming languages, but you don’t need to know it all in order to program effectively. If you see a cryptic message like this, you can often get by without deciphering it. (Of course, if you’re frustrated, ask a neighbor or a staff member for help.) Try to fix the code above so that you can run the cell and see the intended message instead of an error. 2.5 1.5. The Kernel The kernel is a program that executes the code inside your notebook and outputs the results. In the top right of your window, you can see a circle that indicates the status of your kernel. If the circle is empty (), the kernel is idle and ready to execute code. If the circle is filled in (), the kernel is busy running some code. Next to every code cell, you’ll see some text that says In [...] . Before you run the cell, you’ll see In [ ] . When the cell is running, you’ll see In [*] . If you see an asterisk (*) next to a cell that doesn’t go away, it’s likely that the code inside the cell is taking too long to run, and it might 4
be a good time to interrupt the kernel (discussed below). When a cell is finished running, you’ll see a number inside the brackets, like so: In  . The number corresponds to the order in which you run the cells; so, the first cell you run will show a 1 when it’s finished running, the second will show a 2, and so on. You may run into problems where your kernel is stuck for an excessive amount of time, your notebook is very slow and unresponsive, or your kernel loses its connection. If this happens, try the following steps: 1. At the top of your screen, click Kernel , then Interrupt . 2. If that doesn’t help, click Kernel , then Restart . If you do this, you will have to run your code cells from the start of your notebook up until where you paused your work. 3. If that doesn’t help, restart your server.
- Fall '17
- Human height