Lab 9 Tracing and Files
Summary
This lab will give you practice with tracing by adding print
s to your
code, as well as some exercises on file operations.
Lab Setup
- Find your partner
- Download lab09.zip which includes the starter code for non-exercise parts of the lab
- Extract that zip file and move the resulting
lab09
folder into yourcs111
directory on your desktop. - Open Thonny and view the
lab09
files
Table of Contents
Big Questions
- What are the benefits of writing tests for your code?
Show Answer
The primary benefit is developing a deeper understanding of the problem you're trying to solve, by forcing you to think concretely about how a solution will behave, and what the edge cases might be. Of course, another important benefit is being able to build confidence that your solution actually works, and being able to quickly check before submitting your code that it's all working and nothing that you did later broke an earlier function you wrote. - What's the biggest difference between data stored in Python variables and data stored in a file?
Show Answer
Data in Python variables has a type associated with it, and some data types can have complex structures, like lists, so you can represent all sorts of things in a way that the programming language can easily use. In contrast, data stored in a file is essentially just one big string, with no opportunity to organize it. The string can have some kind of internal format, especially using newlines to separate things and perhaps something like a comma or tab to separate items on each line. But for this format to be used in a program, the program has to do the work of converting it to a real data structure (like a list of tuples) before it can be operated on easily using tools like loops.