Lecture 2 — Exercises


These problems are exercises to work on at the end of lecture and submit for a small part of your grade. Normally, solutions will be due within 24 hours of the end of the lecture they are associated with. For these Lecture 2 exercises only, they will be due by the end of Lab 1 so that any problems with submission can be ironed out.

Students are welcome to work on these problems in small groups, but each student should write the final version of their solutions independently. Each student must submit their own solutions.

Getting Started with the Wing IDE

Open up the Wing IDE:

  • You can practice with small sections of Python code by typing in the interpreter in the lower right pane.
  • In order to create a Python program that you save to a file, click File -> New. You can save it to a file by typing File -> Save As
  • As discussed in Lab 0 you should save your programs in an organized manner within your Dropbox folder.
  • Once you have drafted your code to solve a problem or, better yet, have written enough that you are ready to experiment with what you have, click on the green triangle to run your code. You will see the results in the interpreter pane on the lower right.
  • If you do not see the green triangle, you need to save your code to a file first.

Now you are ready to proceed...

Problems for Grade Submission

  1. Write a single line of Python code that converts the temperature 64 from Celsius to Fahrenheit and prints the value. Submit a Python file containing just this single line of code. The output should just be the number that your code produces. Your code must include the use of an expression involving multiplication and a print function call.
  2. Write Python code that creates three variables called length, width and height to store the dimensions of a 16.5 x 12.5 x 5 box. Write additional code that calculates the volume of the box and calculates its surface area, storing each in a variable. Print the values of these variables. Your code must use five assignment statements and two print function calls. Submit a file containing these seven lines of Python code. Your output should be
volume = 1031.25
area = 702.5
  1. Your problem is to determine the output of the Python program shown below. You must submit a text file showing the output. (Hint: there should be two lines with one integer on each line.) While it is possible to just run the program and copy the output, we strongly encourage you to not do this. You need to develop the ability to read code and understand what it will do. You will be tested on it.
z = 2
z = z**2**3
x = 6
x = x**2 + 6 - z // 10 * 2