Paired Programming Activity
Loop Problems, part 2
Activities
I would like you to attempt to complete several small Python scripts working with your partner.
Please try to make your program output look as much like the example as possible and verify it works with the example input provided. If you have difficulty finding the information or understanding how to approach the problem, you should contact me.
To complete this activity, you will need to create the following scripts:
- LOOP 4 - countTimes()
- LOOP 5 - isIn()
- LOOP 6 - howLong()
Replit appears to be slowly breaking Teams for Education. As such, I encourage you to use the autograders on Autolab.cs.uni.edu under Replit Replacement. All three should have valid testers.
LOOP 4
What's in a name?
You are all currently or going to be teachers. You will be surprised at how many times you have classes filled with the same names. In this activity we will count a class list to see how many times a certain name appears.
For testing purposes you can use:
- firstPeriod = ["Lauren" , "Ellie" , "Jared" , "Megan" , "Myriam" , "Lauren" , "Ryan" , "Beth" , "Lauren" , "Beth" , "Susie" , "Lauren" , "Tyler"]
- secondPeriod = ["Jon" , "Tyler" , "Bob" , "Jesse" , "Bob" , "Callie" , "Laura" , "Cora" , "Gabe" , "Jon" , "John"]
- Function name
- countTimes()
- Parameters
- a String, assumed to be a name
- a List, assumed to contain Strings/names
- Return value
- the number of times the given name appears in the class list
- Examples
LOOP 5
He is quite the character
There is this strange little bit of English/literature lore about a book called Gadsby. Gadsby is a 1939 Novel (by Ernest Vincent Wright) that does not contain ANY words that include the letter e. The MOST common letter in the English language. Yep, not ONE e in the entire book.
This function could test that I suppose
- Function name
- isIn()
- Parameters
- a String, assumed to be one letter
- a String, assumed to be a long sentence, paragraph, or even entire story.
- Return value
- True/False based on whether the letter is in the sentence
- For sake of ease in this assignment we are going to assume that asking about "e" is different than asking about "E" or any other upper/lower combo.
- Examples
LOOP 6
TC Works for the UNI Foundation
TC has started working for the UNI Foundation. One of the ways that UNI is able to give scholarships is off of the interest from smart, long-term investments. They are trying to figure out how long it will take them to double their money in particular investments.
- Function name
- howLong()
- Parameters
- An initial investment
- The annual interest rate (put in as a percentage such as 5 or 2.75)
- Return
- The number of years needed until the investment is worth at least twice as much (how long until it has doubled?)
- Examples
NOTE: This is a loop problem. You must use a loop to get credit. DO NOT simply use a formula.