0
0
Pythonprogramming~10 mins

abs() and round() in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the absolute value of -7.

Python
result = [1](-7)
print(result)
Drag options to blanks, or click blank then click option'
Astr
Bround
Cint
Dabs
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using round() instead of abs() will not remove the minus sign.
Using int() or str() won't change the sign of the number.
2fill in blank
medium

Complete the code to round the number 3.14159 to 2 decimal places.

Python
result = round(3.14159, [1])
print(result)
Drag options to blanks, or click blank then click option'
A2
B1
C3
D0
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 0 will round to the nearest whole number.
Using 1 or 3 will round to the wrong number of decimals.
3fill in blank
hard

Fix the error in the code to correctly round the number 5.6789 without decimals.

Python
result = round([1])
print(result)
Drag options to blanks, or click blank then click option'
Around(5.6789)
B'5.6789'
C5.6789
Dint(5.6789)
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing a string instead of a number causes an error.
Calling round() inside round() is incorrect.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their absolute length difference from 4 as values.

Python
words = ['cat', 'house', 'dog', 'tree']
length_diff = {word: abs(len(word) [1] 4) for word in words if len(word) [2] 2}
print(length_diff)
Drag options to blanks, or click blank then click option'
A-
B+
C>
D<
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '+' instead of '-' changes the meaning.
Using '<' instead of '>' filters the wrong words.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys, their rounded lengths as values, only if length is greater than 3.

Python
words = ['apple', 'bat', 'carrot', 'dog']
result = { [1]: round(len(word), [2]) for word in words if len(word) [3] 3 }
print(result)
Drag options to blanks, or click blank then click option'
Aword.upper()
B1
C>
Dword.lower()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using word.lower() instead of uppercase keys.
Using '<' instead of '>' filters wrong words.
Rounding to 0 decimals changes output meaning.