Look at the following Python program (the numbers to the left of the line are line references and not part of the program):
numOfPC = 10 numOfMac = 4 inventory = [numOfPC, numOfMac] def addOne(num): result = num + 1 return result addOne(numOfMac) numOfPC = addOne(numOfPC) inventory[1] = addOne(inventory[1])
numOfPC
, numOfMac
, and inventory
after the program has executed lines 3, 9, 10, and 11. (Hint: when in doubt, review the way we reasoned about programs in class and follow it religiously).
File
menu in the top left corner, click on New Window
(or simply press Ctrl+N on your keyboard). This should open up a new file as we saw in class. Type in the program.print
statements, modify the program so that when you execute it, you can see what are the values of the variables numOfPC
, numOfMac
, and inventory
after lines 3, 9, 10, and 11.FirstLast_HW2-2_Task1.py
. (You need to hand in this program.) Then press F5 to run the program. Do the outputs match your prediction from the first question? If there is a difference, try to explain it. If not, explain your reasoning. Write this solution, as well as your original guesses in a text file called FirstLast_HW2-2_Answers.txt
Copy the stencil code for this assignment to your computer
Write your answers in the text file you used in Task 1. Throughout the stencil code, there are several commented numbers (#1, #2, etc.) scattered around. For each of these break points, we want you to do the following:
~List every user-defined variable and function that currently exists at that line.
~Each variable's type (int, float, string, etc. For lists, specify list type, i.e. list(string), list(int), etc.)
~Each variable's value (for example, 1, 3.14, ["a", "b", "c"], etc.)
If this is still a little confusing, look at the example in the stencil. Once you've finished, double-check your answers by adding print() statements at each break point to see what the variables actually are, like what you did for task 1. Just as in task 1, if the program outputs do not match your prediction, be sure to explain why; you don't have to explain your reasoning if your guesses are correct.
Rename your Python file FirstLast_HW2-2_Task1.py
and your text file FirstLast_HW2-2_Answers.txt
and share them both with cs0931handinfall2015@gmail.com
.
Note: Before you turn in your Python files, make sure they run without any errors (Save your Python file. Then select Run > Run Module
or hit F5
on your keyboard)! If nothing appears in the Shell, don't worry as long as no red error messages appear. If they don't run, i.e. if red stuff starts appearing in the shell, points will be taken off!