Paired Programming Activity
Conditionals
Activities
I would like you to attempt to complete four small Python scripts working with your partner.
These problems will be completed using an editor such as Thonny or IDLE and submitted to Autolab for grading.
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 functions:
- Cond 1 - How old is my dog?
- Cond 2 - Leap Year checker
- Cond 3 - Chinese Zodiac
- Cond 4 - Da Binz Store
Cond 1
How old is that doggy in the window?
Canine West works for the Cedar Bend Humane Society.
Conventional wisdom says that one human year is equivalent to 7 dog years. But it turns out that this is an oversimplification. Veterinarians tell us that it only takes a dog two human years to reach adulthood and then they age much more slowly. They say a more accurate formula is
- One human year is equivalent to 10.5 dog years for the first two years of their life
- After that, each additional human year is 4 dog years
Write a Python script that conforms to the following
- Inputs
- a number of human years that can be a floating point number
- Print Statements
- if the human years is non-negative, prints the equivalent dog age, rounded to 1 decimal place, based on the formula given above
- or
- if the human years is negative, prints "ERROR"
- Example(s)
Cond 2
Is it a Leap Year?
Dr. Cal Lender was just reading up about leap years and he was amazed to find that everything he ever thought about leap year was WRONG. It doesn't actually automatically happen EVERY 4 years.
In fact:
- (1) There is a leap year every year whose number is perfectly divisible by four - except
- (2) for years which are both divisible by 100 and not divisible by 400.
- Rule 2 affects certain century years. For example,
- 1900 is evenly divisble by 4 and not divisible by 400. Rule 2 makes it not a leap year
- 2000 is evenly divisible by both 4 and 400. Rule 2 makes it a leap year.
Write a Python script that conforms to the following
- Inputs
- The year
- Print Statements
- Leap Year
- NOT Leap Year
- Example(s)
Cond 3
Zoe Diak is opening a Chinese restaurant. She decides that she wants to be like most Chinese restaurants and have information about people's birth year and what that means in the Chinese Zodiac.
She reads up on this and discovers that the zodiac cycles one animal per year for every 12 years and then starts over again. In recent years:
-
Year Zodiac Sign 2012 Dragon 2013 Snake 2014 Horse 2015 Sheep 2016 Monkey 2017 Rooster 2018 Dog 2019 Pig 2020 Rat 2021 Ox 2022 Tiger 2023 Rabbit
** Note, the way it is presented on Chinese Placemats is a simplification because the Chinese (Lunar) calendar and years doesn't line up with the Western (Gregorian) calendar. If you were born in January or February it is very likely that you were born before Chinese New Year and thus would be part of the year BEFORE you were born. But we are going to follow the Chinese placemat calendar and pretend that the two align.
Write a Python script that conforms to the following
- Inputs
- asks for the year
- Print Statements
- prints one of 12 Strings based on the table above
- NOTE: You may start by accepting only the 12 years above.
- BUT, you should try to extend this to take ANY valid year AD.
- This should be done by figuring out the pattern and using some math so that all years in the same category are mathematically "manipulated to the same condition"
- (for example, 1925, 1937, 1949, 1961, 1973, 1985, 1997, 2009, 2021, 2033 are all Ox)
- HINT This will use the modulo operator from Week 6. Think about how we handled the odd/even problem earlier this week and how it changes when there are 12 options rather than 2 options.
- prints one of 12 Strings based on the table above
- Example(s)
Cond 4
Whose Bins? DEEZ Bins!
There is a chain of stores around the US called "DaaBin Store." [Yes, this a real store. There is one in Waterloo, IA]
They buy pallets of merchandise weekly and start new sales every week. Things are priced as follows:
- Saturday, everything is $7 each
- Sunday, everything is $5 each
- Monday, everything is $3 each
- Tuesday, everything is $1 each
- Wednesday, a bag of things costs $10 (let's assume that a bag holds 15 things).
- Thursday and Friday they are closed to set up for the next week's sale
Write a Python script that conforms to the following
- Inputs
- asks for the day of the week
- asks for the number of items purchased
- Print Statements
- If the store is open:
- The total cost using the formula above
- If the store is closed:
- "We are closed!"
- If the store is open:
- Example(s)
- NOTES
- Most of this is straight forward. But Wednesday is WEIRD.
- No matter how many items we are buying, we have to purchase a WHOLE (integer) number of bags to put them in.
- 10 items need 1 bag
- 14 items need 1 bag
- 15 items need 1 bag
- 16 items need 2 bags. Unfortunately, the first 15 items fit in a bag together and that ONE last item needs its own bag.
- Think back though some of the math we learned in Week 6 and figure out how we can use those variations of division and remainders (modulo) to consider how many WHOLE bags.



