CS 115 Pre-Lab 2 Instructions

Deadline: Tu 1/27/2015 at 7 AM


Part 1: Review of Week 1 concepts

Review the Week 1 reading on variables and assignment as necessary to complete this section.

  1. In a new browser tab, visit the online Python 3 tutor and enter the following Python code:
    x = "I"
    y = 'see'
    x = "what"
    x = 'you'
    y = "did there!"
    Then click "Visualize execution."
  2. You should now see your code at the top left of the window. The next instruction to be executed is highlighted. Try clicking the "Forward" button once. Your program's output will be displayed in the window just below your program, and the current values of your variables will be displayed on the right.
  3. Slowly click "Forward", and watch as each statement is executed in order. Pay attention to the values of your variables and how they change.
  4. Try to answer Question 1 based on what you observed. If you get stuck, you can click the "First" button in the Online Python Tutor to restart the visualization.

Part 2: Preview of Lab 2

In Lab 2, you will write a text-based program that takes one numeric value from the user and does a bunch of math with it.

In the example below, the user's input is italicized and underlined, and all of the other text is output from the program you'll write:

Enter a numeric value: 10
The area of a square with side length 10.0 is 100.0.
The area of a circle with radius length 10.0 is 314.159.
The volume of a cube with edge length 10.0 is 1000.0.
The volume of a sphere with radius length 10.0 is 4188.790.
The area of an equilateral triangle with side length 10.0 is 43.301.

Here's a different example, where the user enters a value of 5.2:

Enter a numeric value: 5.2
The area of a square with side length 5.2 is 27.04.
The area of a circle with radius length 5.2 is 84.949.
The volume of a cube with edge length 5.2 is 140.608.
The volume of a sphere with radius length 5.2 is 588.977.
The area of an equilateral triangle with side length 5.2 is 11.709.

Here are the formulas to compute these five quantities:

Using any tools you like, answer Question 2 in your pre-lab.

Part 3: Math in Python

Now it's time to translate the math into Python. Question 3 in your pre-lab covers Python math, which we'll discuss in more detail on Tuesday.

To answer this question, refer to the "Arithmetic" section of the Week 2 reading assignment, and use the online tutor if you get stuck.

Part 4: Graphical coordinate system

To draw objects in a graphics window, you can describe a point as a pair of coordinates $\left(x, y\right)$, just like in math. But there is one big difference: in the graphical system, the top left point is $(0, 0)$, and the y-coordinates actually get larger as you go down:
Graphics window coordinate system

The specific values depend on the width and height of the window. For example, if the window is 800x800 pixels (what we'll be using in Lab 2), then the top right point is $(800, 0)$.

Answer Questions 4 and 5 in the pre-lab. Question 5 asks you to think about a 100x100 square centered in the graphics window, like this:
Graphics window with a red square in the center

Question 5 doesn't affect your grade, but we encourage you to give it a try; it's worth thinking about before the lab.

Part 5: Submit the pre-lab (due Tu at 7 AM)

Review your answers, and then click the Next button at the bottom of the Moodle quiz. Once you do that, you should see something similar to this:
Quiz attempt summary

Click the Submit all and finish button. You MUST do this so that your writeup can be graded! Once you have submitted your quiz, you should see something similar to this at the top of your Moodle window. The important part is that the State shows up as Finished.
Quiz confirmation