Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Round numbers up and down with math

Use the math module to find the ceiling and floor of a number. Learn to convert floats to their nearest integers upwards and downwards.

Python practice6 minModules & Standard LibraryBeginnerLast updated March 23, 2026

Problem statement

Given a single numeric value (float or int), return a tuple (ceiling, floor) where 'ceiling' is the smallest integer greater than or equal to the value, and 'floor' is the largest integer less than or equal to the value. Use the math module (math.ceil and math.floor) to compute accurate results for positive and negative numbers as well as exact integers.

Task

Implement a function that returns the ceiling and floor of a given numeric value using Python's math module.

Examples

Basic positive decimal

Input

round_up_down(3.2)

Output

(4, 3)

Ceiling of 3.2 is 4, floor is 3.

Input format

A single numeric value (float or int) passed as the only argument to round_up_down.

Output format

A tuple (ceiling, floor) of two integers returned by the function.

Constraints

Value will be a finite number within a reasonable range (e.g., -10000 <= value <= 10000). Use the math module functions math.ceil and math.floor for correct behavior on negatives.

Samples

Sample 1

Input

round_up_down(-1.7)

Output

(-1, -2)

Ceiling of -1.7 is -1 (less negative), floor is -2 (more negative).