0
0
Pythonprogramming~10 mins

len() function 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 find the length of the list.

Python
my_list = [1, 2, 3, 4]
length = [1](my_list)
print(length)
Drag options to blanks, or click blank then click option'
Acount
Bsize
Clen
Dlength
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'size' or 'count' instead of 'len()'.
Trying to access a property like 'length' instead of calling a function.
2fill in blank
medium

Complete the code to get the length of the string.

Python
word = "hello"
word_length = [1](word)
print(word_length)
Drag options to blanks, or click blank then click option'
Alen
Bcount
Csize
Dlength
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'count' which is a string method but requires an argument.
Using 'size' or 'length' which are not functions in Python.
3fill in blank
hard

Fix the error in the code to correctly get the length of the tuple.

Python
my_tuple = (1, 2, 3)
length = [1](my_tuple)
print(length)
Drag options to blanks, or click blank then click option'
Asize
Blength
Ccount
Dlen
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'size' or 'length' which are not Python functions.
Trying to use 'count' which is a method but needs an argument.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values for words longer than 3 letters.

Python
words = ["apple", "bat", "car", "door"]
lengths = { [1]: [2] for word in words if len(word) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Cword.upper()
Dword.lower()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using word.upper() or word.lower() as keys instead of the original word.
Using the word itself as the value instead of its length.
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 3 letters.

Python
words = ["tree", "sun", "flower", "sky"]
lengths = { [1]: [2] for word in words if len(word) [3] 3 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
D<
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Using the original word instead of uppercase for keys.