Graded Problem Set #2.3
Functions (Familiar Code)
Background
These problems should be completed on your own. Unlike the practice problems, where you are allowed, and even encouraged, to talk about the process with your classmates, these should be attempted on your own. If you have difficulty with these, please reach out to me for assistance or guidance.
These problems will be completed using an editor such as Thonny or IDLE and submitted to Autolab for grading.
Activities
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:
- Func G1 - infieldArea()
- Func G2 - qbCategory()
- Func G3 - timeLeft()
- Func G4 - dogAge()
Func G1
Area inside of a race track
Rusty Fender designs racing tracks. One of the considerations for a race track is how much area is inside of the track for things like the pits and RV parking. He wants a quick and easy way to calculate the area inside of the track.
Write a Python function that conforms to the following
- Function name
- infieldArea()
- Parameter(s)
- length of the straightaways
- radius of the two curves
- Return value
- the the overall area inside of the track described by those dimensions as calculated
- you should not round the answer in any way
- Special Instructions
- Think about the dimensions of a track. A perfect racing "oval" is actually a rectangle closed in by two perfect semi-circles on each end:
- You might want to review python's math module (linked on the front page of our class website) and review math.pi and math.pow
- For your reference:
- a standard high school running track has straightaways of 84.39 meters and curves with a radius of 36.5 meters (example 1 above)
- Bristol Motor Speedway (one of the smaller NASCAR tracks) has straightaways of 650 feet and two slightly different curves with an average radius of 249 feet (example 2 above).
- Think about the dimensions of a track. A perfect racing "oval" is actually a rectangle closed in by two perfect semi-circles on each end:
Func G2
Quartback Passer Rating Category
Steve Lers is a statistician working for the NFL. Part of his job is to keep track of how the Quarterbacks are doing each season. Over the years the NFL has used a statistic called the Quarterback Passer Rating (https://en.wikipedia.org/wiki/Passer_rating) to compare how QBs are doing compared to each other and compared to themselves year over year. The formula (we will look at the actual formula later in the course) produces a score between 0 and 158.3333333. The higher the rating the better season the QB is having. Furthermore, there is some consensus that we can "categorize" the year a player is having using the following analysis.
Rating | Category |
---|---|
0 up to 85 | Bad |
Above 85 but 90 or lower | Mediocre |
Above 90 but 95 or lower | Good |
Above 95 and up to 158.33333 | Great |
Write a Python function that conforms to the following
- Function name
- qbCategory()
- Parameter(s)
- a floating point value assumed to be the quarterback's passer rating score
- Return value
- if the score entered is "valid" [0-158.33333] then it returns the category from the table above
- if the score is invalid then it returns "ERROR"
- Example(s)
Func G3
Time left to our destination
Miles Prower is an over-the-road truck driver. He is interested in figuring out how long it will take him to get to the next exit.
Write a Python function that conforms to the following
- Function name
- timeLeft()
- Parameter(s)
- current speed
- distance to travel
- Return value
- minutes to destination as calculated
- you should not round the answer in any way
- Example(s)
- Special Instructions
- Remember that MPH tells us how many miles he will travel in 60 minutes
Func G4
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 formuma 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 function that conforms to the following
- Function name
- dogAge()
- Parameter(s)
- a number of human years that can be a floating point number
- Return value
- if the human years is non-negative, return the equivalent dog age, rounded to 1 decimal place, based on the formula given above
- or
- if the human years is negative, return a negative one (-1)
- Example(s)