CSC108 Introductory Lab: Handout 2

Original price was: $35.00.Current price is: $25.00.

Rate this product

CSC108 Introductory Lab: Handout 2
1 Handout Instructions
Please visit instructor or TA office hours if you’re feeling lost!
2 Visualizing Program Execution
Visit the Labs page of the course website; for quick reference, it is:
and from the week 2 lab, click on the link for the visualizer. Open and paste the contents of
(found in MarkUs) into the code box.
Click the Visualize Execution button. Then, using the Next button (the right arrow), step through the
code one line at a time and check to see if your guesses on the variables’ values were correct. Notice that the
visualizer displays a memory “address” for each variable and then the object to which that address refers.
After executing line 4, both credits to go and required refer to the same memory address 2. Do you
understand why this is? If you aren’t sure, discuss it with nearby groups or ask your TA.
When you step through the program, were any of the variable values different than the guesses you had
written down? If they were, try to work out what you misunderstood when you were making the guesses.
If you are confused at all, talk with your partner, to other groups or to your TA. Make sure that before you
move on, both partners understand how the variable values are determined at each step.
Switch driver and navigator.
Using the Prev button, reverse the execution of the program until just before line 11. (The line number 11
should be in blue now.) What is the memory address of completed? What is the type of the value at that
address? Now step forward to the next line so that line 11 is finished executing. (The line number 14 should
now be blue.) What memory address does completed have now and what is the type of the object at that
address? Why?
Finally, notice that even though our program changes completed after you’ve finished 10 courses at the end
of second year, it doesn’t update the variable credits to go. Using the Edit this code link, add to the
program one new line of code (and a corresponding comment) that does this.
Visualize the program one more time to confirm that your final value of the variable credits to go is correct.
3 TO SUBMIT: A program in PyCharm
Switch driver and navigator.
Download the file from MarkUs and save it somewhere in your own files.
Open PyCharm now if you don’t already have it open. Select Open from the File menu and navigate to this
saved file.
Switch driver and navigator.
Run the program and type your age.
Notice that the program has a bug! The bug is a logic error which means that all the statements are valid
Python code but they don’t accomplish what the programmer intended. Can you spot what is wrong? The
final doggie age doesn’t match the final age. Change the program so that the final doggie age is correct.
Save the file and rerun it.
4 TO SUBMIT: Solving a Problem
Now we’d like you to work on solving a problem from the Chapter 1 exercises. The problem is called Next
in line:
Save your work in file Remember, like the problems in Chapter 1, you will need to use
input to get input from the keyboard and print to output the answer to the screen. If you finish this
problem, feel free to work through other Chapter 1 exercises as well.
5 Submitting
Submit your and files to MarkUs. MarkUs lets you run some tests on your
code, but you should always do more testing on your own as well!
See you next week!

Scroll to Top