Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Goal: Learn to use positional and keyword parameters with defaults. Assignment: In various fields it is permissible to have a margin of error while performing

Goal: Learn to use positional and keyword parameters with defaults.
Assignment: In various fields it is permissible to have a margin of error while performing certain calculations. For instance, it is sometimes acceptable in accounting if a sum that should be zero turns out to be a small value. Similarly, in the field of Physics and Engineering, if an error is small enough, it can be safely disregarded.
Write the definition of a function named checked_sum that sums two numbers and checks to determine whether the sum is within an acceptable margin of error. The function should have the following parameters:
Two positional-only parameters, which are the numbers to sum
A parameter named target that is the expected sum
A keyword-only parameter named cutoff that has the default value None. If cutoff is set to a value, it defines an acceptable range within which the sum can fall. For example, if cutoff is set to 0.01, it means the calculated sum can be within plus or minus 0.01 of the target value.
If the calculated sum is equal to target, or within the acceptable range of target, the function should return the value of target. Otherwise, the function should display "Error is too big" and return the calculated sum.
Note: If the difference between the result and target is exactly cutoff, it should display the error message and return the result.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems On GPUs In Databases

Authors: Johns Paul ,Shengliang Lu ,Bingsheng He

1st Edition

1680838482, 978-1680838480

More Books

Students also viewed these Databases questions