0
0
Pythonprogramming~10 mins

Tuple methods 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 number of times 3 appears in the tuple.

Python
numbers = (1, 3, 5, 3, 7, 3)
count = numbers.[1](3)
print(count)
Drag options to blanks, or click blank then click option'
Acount
Bfind
Clocate
Dindex
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using index() instead of count().
Trying to use len() on the tuple with a value.
2fill in blank
medium

Complete the code to find the first position of the value 5 in the tuple.

Python
values = (2, 4, 5, 6, 5)
position = values.[1](5)
print(position)
Drag options to blanks, or click blank then click option'
Afind
Bcount
Cindex
Dlocate
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using count() instead of index().
Trying to use find() which is not a tuple method.
3fill in blank
hard

Fix the error in the code to correctly find the index of 10 in the tuple.

Python
data = (10, 20, 30)
pos = data.[1](10)
print(pos)
Drag options to blanks, or click blank then click option'
Aindex
Bfind
Csearch
Dlocate
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using find() which is a string method, not a tuple method.
Trying to use search() or locate() which do not exist.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Python
words = ('apple', 'bat', 'carrot', 'dog')
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 > in the condition.
Putting the word itself instead of its length in the dictionary value.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values for positive numbers.

Python
data = {'a': 1, 'b': -2, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the original key instead of uppercase key.
Using >= or < instead of >.
Using the key as value instead of the actual value.