Challenge - 5 Problems
Absolute and Rounded Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate1:30remaining
Output of abs() with negative float
What is the output of this Python code?
Python
value = -7.25 result = abs(value) print(result)
Attempts:
2 left
๐ก Hint
abs() returns the positive distance from zero.
โ Incorrect
The abs() function returns the absolute value, which means it removes the negative sign and returns 7.25.
โ Predict Output
intermediate1:30remaining
Output of round() with one decimal place
What is the output of this Python code?
Python
num = 3.14159 rounded = round(num, 2) print(rounded)
Attempts:
2 left
๐ก Hint
round() rounds to the nearest value at the specified decimal place.
โ Incorrect
round(3.14159, 2) rounds to two decimal places, resulting in 3.14.
โ Predict Output
advanced2:00remaining
Output of combined abs() and round()
What is the output of this Python code?
Python
value = -2.675 result = round(abs(value), 2) print(result)
Attempts:
2 left
๐ก Hint
abs() removes the negative sign, then round() rounds the number.
โ Incorrect
abs(-2.675) is 2.675. round(2.675, 2) results in 2.68 due to floating point rounding rules in Python.
โ Predict Output
advanced2:00remaining
Output of round() with negative digits
What is the output of this Python code?
Python
num = 1234.5678 result = round(num, -2) print(result)
Attempts:
2 left
๐ก Hint
Negative digits in round() round to tens, hundreds, etc.
โ Incorrect
round(1234.5678, -2) rounds to the nearest hundred, which is 1200.0 because 34.5678 < 50.
๐ง Conceptual
expert2:30remaining
Behavior of abs() and round() with complex numbers
What happens when you run this Python code?
Python
z = complex(-3, 4) result = round(abs(z)) print(result)
Attempts:
2 left
๐ก Hint
abs() returns the magnitude of a complex number.
โ Incorrect
abs(complex(-3,4)) calculates the magnitude sqrt((-3)^2 + 4^2) = 5. round(5) is 5.