Working with VSCode for CS111

Organizing your Files

Create a folder on your computer for your CS111 Python work. You can create this within your file explorer, you don't need to do it within VSCode.

We recommend that you make a subfolder for each lecture/assignment within the overall folder. You can create those either within VSCode or just within the folder explorer system on your computer.

Interacting with Your Code

In Pyret, there was one way to interact with code: run it the type expressions in the interactions window.

In Python, you can run code with or without interacting with it (each involves separate steps). You make this choice using the drop down (down-pointing arrow towards the top right corner, with options for "Run …" or "Debug …").

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Running your file: If you select "Run Python File", VSCode will load and run your file. For this to be effective, there have to be expressions within your file that actually run your functions or tests. Python does not automatically show the results of expressions the way Pyret did.

Interacting with your file: If you want to interact with your file as you did with the Pyret interactions window, you'll need to take the following steps:

  • put the word pass on the last line of your code file
  • click in the window to the left of the line number with pass so that a little red dot appears on that line (see line 28 in the following screenshot)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • Once the dot is in place, select "Debug Python File" in the top right corner.
  • Click on the "DEBUG CONSOLE" tab in the lower half of the window. This will bring up a prompt at the very bottom of the window (just above the orange bar in the following screenshot)
  • Type an expression to run at the lower prompt and hit enter (see the call to pen_cost above the orange bar).

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

If you edit your file …

  • If you are in interactive/debug mode, press the green circle with the arrow that's in the box at the center-top of the above screenshot. That will reload your file and set you up at the prompt again. (That strip of icons are the debugging controls, which we will learn more about in the coming days.)
  • If you were just in run mode, you can just run the file again (either by selecting the dropdown at the top or just clicking on the right-pointing arrow next to the dropdown).

Troubleshooting

  • I didn't get the prompt in the debug console. Make sure that you have the red dot to the left of the line number where you wrote pass. If there's no dot, just click to the left of the line number and the dot should appear.
  • I edited my file but the change isn't visible. Make sure you are pressing the green circle in the short bar of debug controls (at the center top of the previous screenshot), rather than starting a new debug session using the dropdown.

Coming later …

We will talk more in the coming days about what the red dots mean and how to track down errors in your code. We'll add instructions here as we cover them.