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 - calculateBill()
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
Golden Panda has the best Mu Shu Pork
A particular Chinese buffet determines the price of your meal based on the age of the guests.
- Guests 2 and younger are free
- Children between 3 and 12 are $4.50
- Seniors 65 and over cost $9.50
- All other customers cost $11.00
Write a Python function that conform to the following:
- Function name
- calculateBill()
- Parameters
- A list of integers
- What it does
- Loops through the list of ages in the list and calculates the total bill based on the prices above.
- Any values that are not positive integers should be ignored
- For this assignment you can assume that all values will be integers, but there may be negative values which are garbage and therefore, should be ignored.
- Return value
- The total bill rounded to two decimal places
- Examples