0
0
Intro to Computingfundamentals~10 mins

Search and find operations in Intro to Computing - 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 index of the number 7 in the list.

Intro to Computing
numbers = [3, 7, 1, 9]
index = numbers.[1](7)
print(index)
Drag options to blanks, or click blank then click option'
Aindex
Bfind
Csearch
Dlocate
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that doesn't exist like 'find' or 'search'.
Confusing the method with one that returns True/False.
2fill in blank
medium

Complete the code to check if the word 'apple' is in the list.

Intro to Computing
fruits = ['banana', 'apple', 'cherry']
if 'apple' [1] fruits:
    print('Found it!')
Drag options to blanks, or click blank then click option'
Ainside
Bon
Cat
Din
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'on' or 'at' which are not valid Python keywords for membership.
Trying to use a method instead of a keyword.
3fill in blank
hard

Fix the error in the code to find the position of 5 in the list.

Intro to Computing
values = [2, 4, 5, 6]
position = values.[1](5)
print(position)
Drag options to blanks, or click blank then click option'
Afind
Bsearch
Cindex
Dlocate
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'find' or 'search'.
Confusing with string methods.
4fill in blank
hard

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

Intro to Computing
words = ['cat', 'house', 'tree', 'a']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself instead of its length.
Using '<' instead of '>' in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 2 letters.

Intro to Computing
words = ['dog', 'cat', 'a', 'bird']
result = { [1]: [2] for w in words if len(w) [3] 2 }
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C>
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself instead of uppercase for keys.
Using '<' instead of '>' in the condition.
Mixing variable names.