This is a lab assignment and so you will not be submitting it. However, the concepts and practice will help you on both the homework and quizzes so I encourage you to make a serious effort on it during class and consider finishing it outside of class.

I recommend making a folder for today’s lab in COURSES as you usually do.

Exercise 1

Debugging poorly written and buggy code is a valuable skill. To help you practice it, I’ve written a painfully bad program called (or is it??) that attempts to convert Celsius temperature to Fahrenheit. That calculation should be (C * 9/5) + 32 where C is the value in Celsius. Download this code, move it to your folder for today, and open it in VSCode.

This code is both badly styled, making it very difficult to read, and has a bug or two. You should aim to improve it, which will probably involve:

  • Drawing out a memory diagram of what is going on with each of the variables
  • Fixing variable names
  • Getting it to output something
  • Fixing a logical bug
  • Making the variable names useful and rearranging things
  • Writing comments and documentation

Exercise 2

For each of the following code snippets, predict answers to the following:

  • When will evaluation of each variable occur?
  • What value(s) will each variable be assigned?
  • What will the reference diagram look like?

Then click through the steps to check your predictions and figure out anything that you got wrong.

In this last snippet, PythonTutor reorders the values a bit strangely (and unnecessarily), but the values are still correct, so be sure to go through the steps slowly to catch that and be sure of what is happening.

Exercise 3

The word ‘variable’ is used in mathematics, programming, and everyday speech and each use is slightly different. List out as many similarities and differences as you can between what ‘variable’ means in each of these contexts.

Exercise 4

Consider a bizarro alternate universe in which an hour is 47 minutes long. Each day still has 24 hours and each year still has 365 days (you can ignore leap years).

Write a Python program that will print out how many minutes longer a year is in the 60-minute universe than in the 47-minute universe. Extend your program to print out how many days that value is equal to (in both worlds).


This lab is adapted from labs by Profs. James Ryan and Eric Alexander.