Challenge - 5 Problems
Rounding Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of np.round() with decimals parameter
What is the output of this code snippet?
NumPy
import numpy as np arr = np.array([1.234, 2.345, 3.456]) result = np.round(arr, decimals=1) print(result)
Attempts:
2 left
💡 Hint
np.round rounds each element to the specified number of decimal places.
✗ Incorrect
np.round with decimals=1 rounds each number to one decimal place, so 1.234 becomes 1.2, 2.345 becomes 2.3, and 3.456 becomes 3.5.
❓ Predict Output
intermediate2:00remaining
Output of np.floor() on negative and positive values
What is the output of this code?
NumPy
import numpy as np arr = np.array([-1.7, -0.2, 0.2, 1.7]) result = np.floor(arr) print(result)
Attempts:
2 left
💡 Hint
np.floor returns the largest integer less than or equal to each element.
✗ Incorrect
For negative numbers, floor goes to the next lower integer: floor(-1.7) is -2, floor(-0.2) is -1. For positive numbers, floor truncates decimals: floor(0.2) is 0, floor(1.7) is 1.
❓ Predict Output
advanced2:00remaining
Output of np.ceil() with mixed values
What does this code print?
NumPy
import numpy as np arr = np.array([1.1, 2.5, 3.0, -1.1, -2.5]) result = np.ceil(arr) print(result)
Attempts:
2 left
💡 Hint
np.ceil returns the smallest integer greater than or equal to each element.
✗ Incorrect
np.ceil returns the smallest integer greater than or equal to each element (towards +∞). 1.1→2, 2.5→3, 3.0→3, -1.1→-1, -2.5→-2.
❓ Predict Output
advanced2:00remaining
Number of elements after rounding and filtering
How many elements are in the array after rounding to 0 decimals and filtering values > 2?
NumPy
import numpy as np arr = np.array([1.9, 2.1, 2.5, 3.4, 1.2]) rounded = np.round(arr, decimals=0) filtered = rounded[rounded > 2] print(len(filtered))
Attempts:
2 left
💡 Hint
Round first, then count how many are greater than 2.
✗ Incorrect
Rounded array is [2., 2., 2., 3., 1.]. Values > 2 are only 3., so count is 1.
🧠 Conceptual
expert3:00remaining
Understanding behavior of np.round() with negative decimals
What is the output of this code snippet?
NumPy
import numpy as np arr = np.array([123.45, 678.91, 234.56]) result = np.round(arr, decimals=-1) print(result)
Attempts:
2 left
💡 Hint
Negative decimals rounds to the left of the decimal point.
✗ Incorrect
Rounding with decimals=-1 rounds to the nearest 10: 123.45 to 120, 678.91 to 680, 234.56 to 230.