TLP - Programming Maintenance
Week 6 - Reading Code - Birthday Edition
This assignment is based on data collected by Kimberly McCoy-Parker during the Choose Your Own Data assignment in the FOP class.
Background
One of the skills we need to gain as a programmer (and as a programming teacher) is reading someone else's code to figure out what it does. In this activity you will read several functions and try to figure out what they do and how they do them.
You will need the following files to complete this activity
Task
Before you begin, take a moment to explore the data file you downloaded so you have a sense for what it represents.
Answer the following questions about the code in birthrates.py
- What does functionOne() do?
- Begin by ONLY looking at the code and trying to figure out what it will do without executing the code in Thonny.
- When you think you know, test your theory by invoking the command by running functionOne(1976) at the command line.
- Explain what functionOne() does.
- What does functionTwo() do?
- Begin by ONLY looking at the code and trying to figure out what it will do without executing the code in Thonny.
- When you think you know, test your theory by invoking the command by running functionTwo(7,4) at the command line.
- Explain what functionTwo() does.
- What does functionThree() do?
- Begin by ONLY looking at the code and trying to figure out what it will do without executing the code in Thonny.
- When you think you know, test your theory by invoking the command by running functionThree("December",25) at the command line.
- Explain what functionThree() does.
- What is the advantage of this version over functionTwo()?
- What is the purpose of line 30/31 (notice I say line. Singular. This is because that is only one command that wraps from line 30 onto line 31)?
- Why is the first element of the list on line 30 the zero-length string? (The value "")
- What is the purpose of the factored variable? (lines 32, 35, and 46)?
- What is the purpose of lines 36 and 37?
- What does functionFour() do?.
- Begin by ONLY looking at the code and trying to figure out what it will do without executing the code in Thonny.
- When you think you know, test your theory by invoking the command by running functionFour() at the command line.
- NOTE: This function may take 1-2 minutes to complete.
- Explain what functionFour() does.
- What is the purpose of the list in line 54?
- What is the purpose of the combo of for loops in lines 59 and 60?
- Why does this function take so long to run?
You should submit your answers to these questions on Blackboard.