logo CodeStepByStep logo

roundoff_credits

Language/Type: Python float errors

The following code was intended to print a message, but it produces incorrect output. Due to round-off error, the expression 3.2 * 3 in Python does not exactly equal 9.6.

Fix the code to print the correct message in each case. To avoid round-off errors, modify the code so that it will print "You earned the correct amount of credits!" if the credits are within a margin of 0.1 from 9.6. (Your code should still examine the value of the variable credits and not the value of gpa.)

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.