To receive full credit, for each exercise you should do the following:
Design: First, design a Python class as requested in the exercise. Type in your class definition.
Check: Run the provided test code. Does your actual output agree with the given correct output?
Evaluate: If the actual output does not match the expected output, keep experimenting, consult the textbook or Python documentation, ask a friend or TA or professor, etc. until you can fix your class definition and explain what your misunderstanding(s) were. (You do not need to do anything for step 3 if the outputs already agree exactly.)
You should consider the code in each exercise separately from the other exercises.
Write a Python class BouncyBall, which represents a bouncy ball containing a certain amount of air.
BouncyBall
bounce()
Bounce!
Thupp.
inflate()
BANG!!!
Sorry, you cannot bounce this ball! It has exploded.
To test your class, you can type in and run the following code:
def main(): b = BouncyBall() for i in range(6): b.bounce() b.inflate() b.bounce() b.bounce() for i in range(5): b.inflate() b.bounce() main()
If your definition of BouncyBall is correct, main() should produce the following output:
main()
Bounce! Bounce! Bounce! Bounce! Thupp. Thupp. Bounce! Thupp. BANG!!! Sorry, you cannot inflate this ball! It has exploded. Sorry, you cannot bounce this ball! It has exploded.
Write a Python class Gradebook which works as follows:
Gradebook
add_grade(g: int)
g
add_ec(ec: int)
ec
average()
You can test your implementation of Gradebook by running the code below:
def main(): gb = Gradebook() gb.add_grade(90) gb.add_grade(83) gb.add_grade(97) gb.add_ec(10) print(gb.average()) main()
If your definition of Gradebook is correct, this should print 93.33333333333333.
93.33333333333333