CSC 1001 — Week 1 Lab: Reading Code Like a Human

Understand (Partner)

Goal: Become more comfortable reading Python code. Learn why some code is easier/harder to understand than others.

Below are six code chunks, labeled A–F. Each one does something simple, but they come in pairs — two chunks per task. As a group of two, for each chunk:

  1. Read it line by line and figure out what it does and what each variable (named storage box) represents. (By what it does we mean what is the goal or the overall outcome.)
  2. Decide: is this code easy or hard to understand?
  3. Write down why — point to specific things (names, structure, comments, spacing) rather than just "it's confusing."
  4. Try to find the chunk's "partner" — the other chunk doing the same task.

Each of you will turn this in separately, so make sure you each have a copy.


Chunk A

# Calculate the area of a rectangle
length = 8
width = 5
area = length * width
print("The area is:", area)

Chunk B

a=12
b=3
c=5
d=a*b+c
print(d)

Chunk C

f="Jordan"
l="Lee"
g=f+" "+l
print(g)

Chunk D

x=8
y=5
z=x*y
print(z)

Chunk E

# Calculate the total cost of ordering pizza
price_per_pizza = 12
number_of_pizzas = 3
delivery_fee = 5

total_cost = (price_per_pizza * number_of_pizzas) + delivery_fee
print("Your total cost is:", total_cost)

Chunk F

first_name = "Jordan"
last_name = "Lee"
full_name = first_name + " " + last_name
print("Welcome,", full_name)

Challenge Chunks

If you still have time (or while you're waiting for Anaconda to install) try to figure these out. They don't have matches.

Chunk G

# Split a dinner bill evenly among friends, including tip
subtotal = 64.50
tip_percent = 0.20
number_of_friends = 4

tip_amount = subtotal * tip_percent
total_bill = subtotal + tip_amount
amount_per_person = total_bill / number_of_friends

print("Each person owes:", round(amount_per_person, 2))

Chunk H

p=80.00
d=0.25
t=0.055
q=p-(p*d)
r=q+(q*t)
print(round(r,2))

Reflection questions

  1. What did I learn (big picture)?
  2. How can I ensure I'm writing easy to understand code, not hard to understand code?

Do

Goal: Get Python and Jupyter Notebook running, then run and modify a simple program.

Work through these steps in order. If something doesn't look like the description, raise your hand before moving on — small setup issues compound fast.


Step 1: Download and Install Anaconda

Anaconda installs Python along with Jupyter Notebook and a graphical launcher called Anaconda Navigator, so you won't need the command line today. (You'll use the command line later in the course — this just isn't a day-1 tool.)

  1. Open a browser and go to **https://www.anaconda.com/download
  2. In the Download Now section, click the link that says Skip Registration
  3. Download the Anaconda Distribution version of the Windows 64-bit Graphical Installer
  4. Once downloaded, open the installer file.
  5. Click through the setup screens using the default/recommended options:
    • Agree to the license
    • Choose "Just Me" when asked who to install for
    • Leave the install location as the default
    • Leave the checkboxes on the "Advanced Installation Options" screen at their defaults and click Install
  6. This install is large (a few GB) and can take 10–15 minutes. This is a good moment to read ahead or ask questions while it runs.
  7. Uncheck Launch Anaconda Navigator and Welcome to Anaconda.
  8. Click Finish when done.

Step 2: Open Anaconda Navigator

  1. Click the Start Menu and type Anaconda Navigator (NOT Anaconda Prompt).
  2. Click to open it. (First launch may take a minute or two to load — this is normal.)
  3. You'll see a home screen with tiles for different applications (PyCharm, Anaconda Prompt, JupyterLab, etc).
  4. Anaconda wants to update. Don't worry about this. You can click the Don't tell me again box and then say Update later or Don't Update.

Step 3: Launch Jupyter Notebook

  1. Scroll down to find the Jupyter Notebook tile.
  2. Click the Launch button on that tile.
  3. A browser tab will open automatically showing a file browser — this is the Jupyter home page.
  4. Leave the Anaconda Navigator window open in the background — closing it may shut down your notebook.

Step 4: Create a New Notebook

  1. On the Jupyter home page, click the New button (upper right). (You can also click File in the upper left, then New, then Notebook)
  2. Select Python 3 (ipykernel).
  3. A new tab opens with an empty notebook containing one blank cell.
  4. If you look in the top line, you'll see your notebook is called Untitled.ipynb. To save it as a new file, go to File -> Save Notebook As and save it as Lab1.ipynb

Step 5: Run "Hello World"

  1. Click into the first (empty) cell.

  2. Type:

    print("Hello, world!")
  3. Press Shift + Enter to run the cell.

  4. You should see Hello, world! appear directly below the cell.


Step 6: Alter the Code

  1. Click back into the same cell and change the text so it says something different.
  2. Press Shift + Enter to run it again and confirm the new output.

Step 7: Make the Output Print on Two Lines

Using the next cell, write code so that the output shows on two separate lines:

welcome to msoe
programming is fun

Run the cell (Shift + Enter) and confirm both lines appear, one under the other.


Step 8: Take a Screenshot and Submit

  1. Press Windows key + Shift + S to open the Snipping Tool.
  2. Use the selector to take a screenshot of your code and output from Steps 6 and 7.
  3. The snip is copied to your clipboard — paste it (Ctrl+V) into a Word doc.
  4. Save the file and submit it as instructed for this lab.

If You Finish Early: Run the "Understand" Code Chunks

Go back to the six code chunks from the earlier part of this lab (the good/bad variable naming examples).

  1. In your Jupyter notebook, click + to add a new cell below your current one.
  2. Copy and paste one chunk into the new cell.
  3. Run it (Shift + Enter) and look at the output.
  4. Ask yourself:
    • Did it do what you expected before running it?
    • If not, why not?
  5. Repeat for a few more chunks, then jot down a sentence or two comparing your prediction to what actually happened.

Troubleshooting Tips