0
0
Pythonprogramming~10 mins

Why built-in functions are useful in Python - Test Your Understanding

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

Complete the code to use a built-in function that finds the length of a list.

Python
numbers = [1, 2, 3, 4, 5]
length = [1](numbers)
print(length)
Drag options to blanks, or click blank then click option'
Alen
Bcount
Csize
Dlength
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'size' or 'length' which are not built-in functions in Python.
Trying to use 'count' which counts occurrences of a value, not list length.
2fill in blank
medium

Complete the code to convert a string to uppercase using a built-in function.

Python
word = "hello"
upper_word = word.[1]()
print(upper_word)
Drag options to blanks, or click blank then click option'
Atitle
Bcapitalize
Clower
Dupper
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'lower' which makes letters small.
Using 'capitalize' which only changes the first letter.
3fill in blank
hard

Fix the error by completing the code to find the maximum number in a list using a built-in function.

Python
values = [10, 20, 30, 40]
max_value = [1](values)
print(max_value)
Drag options to blanks, or click blank then click option'
Amaxnum
Bmax
Cmax_value
Dmaximum
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'maximum' which is not a built-in function.
Trying to use variable names as functions.
4fill in blank
hard

Fill both blanks to create a dictionary with word lengths only for words longer than 3 letters.

Python
words = ['cat', 'elephant', 'dog', 'giraffe']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '<' instead of '>' which selects shorter words.
Putting 'word' instead of 'len(word)' for the dictionary values.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values for words longer than 4 letters.

Python
words = ['apple', 'bat', 'carrot', 'dog']
result = { [1]: [2] for w in words if len(w) [3] 4 }
print(result)
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C>
Dw.lower()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'w.lower()' instead of uppercase for keys.
Using '<' instead of '>' for filtering.
Putting 'w' instead of 'len(w)' for values.