Answer the following questions briefly with at most 300 characters per question!
Q1: In what way is the binary representation of int
objects similar to the decimal system taught in elementary school?
< your answer >
Q2: Why may objects of type bool
be regarded a numeric type as well?
< your answer >
Q3: Colors are commonly expressed in the hexadecimal system in websites (cf., the HTML and CSS
formats).
For example, #000000#000000, #ff9900#ff9900, and #ffffff#ffffff turn out to be black, orange, and white. The six digits are read in pairs of two from left to right, and the three pairs correspond to the proportions of red, green, and blue mixed together. They reach from 016=010 for 0% to ff16=25510 for 100% (cf., this article for an in-depth discussion).
In percent, what are the proportions of red, green, and blue that make up orange? Calculate the three percentages separately! How many bytes are needed to encode a color? How many bits are that?
< your answer >
Q4: What does it mean for a code fragment to fail silently?
< your answer >
Q5: Explain why the mathematical set of all real numbers R can only be approximated by floating-point numbers on a computer!
< your answer >
Q6: How do we deal with a float
object's imprecision if we need to check for equality?
< your answer >
Q7: What data type, built-in or from the standard library , is best suited to represent the transcendental numbers
π and e?
< your answer >
Q8: How can abstract base classes, for example, as defined in the numerical tower, be helpful in enabling duck typing?
< your answer >
Motivate your answer with one short sentence!
Q9: The precision of int
objects depends on how we choose to represent them in memory. For example, using a hexadecimal representation gives us 168 digits whereas with a binary representation an int
object can have at most 28 digits.
< your answer >
Q10: With the built-in round() function, we obtain a precise representation for any
float
object if we can live with less than 15 digits of precision.
< your answer >
Q11: As most currencies operate with 2 or 3 decimals (e.g., EUR 9.99), the float
type's limitation of at most 15 digits is not a problem in practice.
< your answer >
< your answer >
Q13: The following code fragment raises an InvalidOperation
exception. That is an example of code failing loudly.
float("inf") + float("-inf")
< your answer >
Q14: Python provides a scientific
type (e.g., 1.23e4
) that is useful mainly to model problems in the domains of physics or astrophysics.
< your answer >
< your answer >
**Q16**: The Decimal
type from the decimal module in the standard library
allows us to model the set of the real numbers R precisely*.
< your answer >
**Q17**: The Fraction
type from the fractions module in the standard library
allows us to model the set of the rational numbers Q precisely*.
< your answer >