In a file called change.py
, create a function that takes
a dollar amount (in cents) and returns the smallest number of coins
(quarters, dimes, nickles, and pennies)
necessary to represent the specified amount of change.
In a file grades.py
, create a function
convert_to_letter_grade
. The function takes a numeric
grade from 0 to 100, and
prints the associated letter grade using the following scale:
Note that square brackets mean inclusive, and parenthesis means exclusive.
Create a Python function called
batting_average(appearances)
in a file with the same
name. The function parameter, appearances, is a list of ints
that encodes the results of a baseball player's appearances at
batting. Each plate appearance can be interpreted as follows:
4 | Home Run |
3 | Triple |
2 | Double |
1 | Single |
0 | Walk |
-1 | Out |
The function should return the batting average for the plate appearances in the list. The batting average can be computed using the following equations:
at_bats = plate_appearances - walks
hits = singles + doubles + triples + home_runs
batting_average = hits / at_bats
>> print(batting_average([1, 1, -1])) 0.6666666666 >> pedroia_at_bats = [-1, 1, -1, -1, 1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 0, -1, 0, -1, -1, -1, 2, 1, -1, -1, -1, -1, 1, 0, -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, 0, -1, 1, 1, -1, -1, 2, 0, -1, -1, -1, -1, -1, -1, -1, 1, -1, 2, -1, -1, -1, -1, -1, -1, -1, 1] >> print(batting_average(pedroia_at_bats)) 0.25396825396825395