Paired Programming Activity
Functions (Familiar Code)
Partners
Activities
I would like you to complete four Python functions 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 functions. You may make them all in the same file on Replit.
- Func 1 - howFar()
- Func 2 - discountPrice()
- Func 3 - zodiac()
- Func 4 - daaBins()
Func 1
How Far
Wayne Ningmoon teaches middle school science. He is currently teaching a unit on space exploration. He wants your help calculating where the Voyager 1 spacecraft currently is located.
Write a Python function that conforms to the following
- Background
- Voyager 1 was launched by NASA on September 15, 1977.
- It is the farthest-traveling Earth-made object.
- It actually left the bounds of our solar system in August of 2012.
- As of April 1, 2022 the spacecraft was located ~14,500,000,000 miles from the sun.
- It is traveling away from the sun at a speed of ~38,027 miles per hour.
- Function Name
- howFar()
- Parameter(s)
- Days since April 1, 2022
- Return value
- the approximate distance between the sun and Voyager 1 based on the previous information
- Example(s)
- Special Instructions
- The calculations above are estimates. To see the actual distance right now you can visit the Voyager status page on the NASA website.
Func 2
Discount Price
Brice Tagg wants you to create a program to help her calculate sale prices in her store.
Write a Python function that conforms to the following
- Function name
- discountPrice()
- Parameter(s)
- original price (of an item)
- percentage off
- Return value
- the sales price for the item as calculated
- you should not round the answer in any way
- Example(s)
Func 3
The Year of the Panther
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 function that conforms to the following
- Function name
- zodiac()
- Parameter(s)
- the year (as a number)
- Return value
- the String representing the corresponding animal from above)
- Example(s)
- Special Instructions
- You should be able to handle ANY year. Notice that it will be impossible to do this with conditionals looking for specific years.
- 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 uses one of the mathematical operators we looked at earlier that was new to you and I keep saying is a powerful operator in programming.
Func 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 function that conforms to the following
- Function name
- daaBins()
- Parameter(s)
- Items Purchased (integer)
- Day of the week (String)
- Return value
- the total of your bill on a day they are open
- -1 if it is a day they are closed
- Note, that this is a change from the last time you saw this problem
- Since this function returns a number under "proper" functionality, it is normally good form to have it return a number during an error.
- The standard error value in programming is a -1 (assuming that isn't a "valid" value itself)
- Example(s)
- Special Instructions
- Notice that Wednesdays are weird because things are sold by the bag, not the piece. We are going to assume that exactly 15 things fit in a bag and if you don't fill a bag that's your problem. So this means 15 items cost $10 but 16 items cost $20 because you had to buy a second bag.