Recall & Review
beginner
What does the
abs() function do in Python?The
abs() function returns the absolute value of a number, which means it removes any negative sign and gives the distance from zero.Click to reveal answer
beginner
How does the
round() function work in Python?The
round() function rounds a floating-point number to the nearest whole number or to a specified number of decimal places.Click to reveal answer
beginner
What will
abs(-7.5) return?It will return
7.5 because abs() removes the negative sign and returns the positive value.Click to reveal answer
beginner
What is the result of
round(3.14159, 2)?It returns
3.14 because it rounds the number to 2 decimal places.Click to reveal answer
beginner
Can
round() be used without specifying decimal places? What happens then?Yes, if you use
round() without the second argument, it rounds the number to the nearest whole number (integer).Click to reveal answer
What does
abs(-10) return?✗ Incorrect
abs() returns the positive value of the number, so abs(-10) is 10.What is the output of
round(4.678)?✗ Incorrect
Without specifying decimal places,
round() rounds to the nearest whole number. Since 4.678 is closer to 5, it returns 5.Which function would you use to get the positive value of a number?
✗ Incorrect
abs() returns the absolute (positive) value of a number.What does
round(2.345, 1) return?✗ Incorrect
It rounds to 1 decimal place. The hundredths digit is 4 (<5), but the thousandths digit is 5, so it rounds up to 2.4.
If you want to round a number to zero decimal places, what should you do?
✗ Incorrect
Using
round(number) or round(number, 0) rounds the number to zero decimal places (nearest whole number). Note that round(number) returns an int, while round(number, 0) returns a float.Explain how the
abs() function works and give an example.Think about how distance from zero is always positive.
You got /3 concepts.
Describe how to use the
round() function to round a number to 3 decimal places.Remember the second number tells how many digits after the dot you want.
You got /3 concepts.