CPSC120
Fundamentals of Computer Science

In-class Activity 17

  1. What is the binary number 1010.0101 in decimal?

  2. What is the decimal number 14.5625 in binary?

  3. For each of the following numbers specify whether it can be represented exactly with a Python float value:

    a.

        1/3

    b.

        1/4

    c.

        10.0 ** 10

    d.

        10.0 ** 10 ** 10

    e.

        1234567890.0e100

    f.

        123456789012345678.0
  4. Write a Python program that prints 0.1 and decimal.Decimal(0.1).

  5. Write a Python program that prints the result of summing 0.1 ten times.

  6. Write a Python program that prints the result of the comparison 0.3 == 0.1 + 0.2.

  7. Write a Python program that uses the built-in round function to print the result of rounding 2. 675 to two decimal places.