Computers and Technology
Computers and Technology, 25.10.2021 23:30, SMNS625

Write a class that represents and defines operators for Interval numbers, which are represented by a pair numeric values: int, float or mixed. We use intervals to represent approximate numbers, whose exact value we do not know. For example, in physics we might know that the acceleration produced by the the force of gravity (g) at sea level is 9.8 m/s2+/- .05 m/s2, which we will write as 9.8(+/-.05) m/s2. With this class we can perform numeric calculations on Interval objects, which automatically keep track of the precision for each calculated value For example, the formula sqrt(d/(2*g)) computes the amount of time it takes for an object at sea level to fall a given distance (d) in a vacuum. Given our approximation for g, and a distance that is 100(+/-1) m, we can use the Interval class to compute the amount of time it takes for an object to drop this amount as follows, including the precision with which we know the answer. Interval. mid_err(9.8,.05) Interval. mid-err(100,1) (d/(2*g)) . sqrt() d = t print(t) So, with g known +/-.05 m/s-, and d known +/-1 m, the results print as 2.258792382 6805945(+/-0.01 7056289680373204), which indicates that the time will be somewhere between about 2.24 and 2.28 seconds, having a relative error of about 7.6%. Note that each Interval object will store the minimum and maximum value in the interval. So 9.8(+/-05) is stored as an Interval with a minimum of 9.75 and a maximum of 9.85 Details
1. Define a class named Interval in a module named intervalpy
2. Define an init method that has two parameters: their arguments specify the minimum and maximum values in the interval respectively. Store them in the self variables min and max. Programmers will not use this method directly to construct Interval objects; instead, they will use the static Interval. min max and Intervalmid err methods (described below) For information about static methods, read the Class Review lecture notes (look for the entry on Static Methods near the bottom, before the problems)
3. Define a static min max method that has two parameters; their arguments specify the minimum and maximum values in the interval. The second parameter is optional, with None as its default value. This method should raise an AssertionError exception, with an appropriate message, if
(a) the first argument is not an int or float numeric type or
(b) if the second argument is not a numeric type or None, or
(c) the first argument is greater than the second; if the second argument is None, use the first argument for botłh the minimum and maximum value (creating an interval with one value representing exactly that number) Return the appropriate Interval object.
4. Define a static mid err method that has two parameters; their arguments specify the middle value and the +- error for the interval. The second parameter is optional, with 0 as its default value. This method should raise an AssertionError exception, with an approprate message, if
(a) the first argument is not an int or float numeric type, or
(b) if the second argument is not a numeric type, or
(c) if the second argument is negative. Return the appropriate Interval object. For example, Interval. mid err(9.8.05). would produce the same object as Interval. min max(9.75,9.85)

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 04:10, cvbnkifdfg
2pointswho was mikhail gorbachev? oa. a russian leader who opposed a coupob. a polish leader who founded the labor union "solidarityoc. a soviet leader who called for a closer relationship with the unitedstates, economic reform, and a more open societyd. a soviet leader who called for more oppression in the soviet union
Answers: 3
image
Computers and Technology, 23.06.2019 16:30, mirmir62
Which of the following is not an enhancement to the standard wiki to make it more attractive for corporations? encryptionwork spacespermission toolspredictive text
Answers: 2
image
Computers and Technology, 23.06.2019 18:00, sophx
Apunishment or the threat of punishment used to enforce conformity. select the best answer from the choices provided t f
Answers: 1
image
Computers and Technology, 24.06.2019 01:10, jaileen84
Create a program that will take in a single x and y coordinate as the origin. after the input is provided, the output should be all of the coordinates (all 26 coordinates read from the “coordinates. json” file), in order of closest-to-farthest from the origin.
Answers: 1
Do you know the correct answer?
Write a class that represents and defines operators for Interval numbers, which are represented by a...

Questions in other subjects:

Konu
Mathematics, 11.03.2020 00:43