CS 115 Lab 3, Setup and Practice

[Back to Lab 3]


Setup

  1. If the machine was on when you started using it, reboot it to MacOS.
  2. Follow these procedures to mount your blue home-directory on the local machine and create a PyCharm project (call it Lab03). You will use PyCharm in the next part, but, it is important that you set up your project now so that if you run into any issue, we can resolve them quickly.
  3. Download the graphics.py library to be used in this lab (On Macs, Right-click and then select "Download Linked File As...").

Practice

  1. Answer Question 1 in your writeup (on Moodle).
  2. In a new browser tab, visit the online Python 3 tutor and enter the following Python code:
    for i in range(3):
        print('Cupcakes!')
    Then click "Visualize execution."
  3. Click the "Forward" button to step through the code, instruction by instruction. Pay attention to how the variable i changes (shown on the right side of the screen).
  4. Using the visualizer to help you, answer Questions 2 and 3 in your writeup. Pay attention to both the program output (below your code) and the global variables (to the right).

    Your answer to Question 3 should be a comma-separated list with spaces between the values.
    For example: 8, 9, 10

  5. Now click "Edit code" in the Python visualizer and enter the following code:
    for j in range(2, 8):
        print('Marshmallows!')
    Visualize this code and answer Questions 4 and 5 in your writeup.
  6. Now try...
    for k in range(8, 2):
        print('Thin Mints (TM)!')
    Visualize this program and answer Questions 6 and 7 in your writeup.
  7. Now try...
    x = 5
    for i in range(1, 6):
        x = i
    Visualize this program and answer Question 8 in your writeup.
  8. Now try...
    x = 5
    for i in range(1, 6):
        x = x + i
    Visualize this program and answer Question 9 in your writeup.
  9. Begin Part A.