Problem 139637 · medium · Level 01 Prerequisites & Setup

Four Ways to Round

functions · rounding · type conversion · math module · tuples

Python offers several ways to turn a float into a whole number, and they do not always agree. Write rounding_report(x) that returns a tuple of four integers:

(int(x), round(x), math.floor(x), math.ceil(x))

in that order, computed with the built-in int and round and the math module (already imported). Try a few negative numbers and numbers ending in .5 to see how they differ.

Examples

Input:  x = 3.7
Output: (3, 4, 3, 4)
Input:  x = -2.5
Output: (-2, -2, -3, -2)

Constraints

  • -10**9 <= x <= 10**9

Goals

  • Tell int(), round(), math.floor() and math.ceil() apart
  • See how each one treats negative numbers and .5 values
Starting Python…