0
0
Intro to Computingfundamentals~10 mins

Search engines and how they find information 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 start a simple search by checking if the keyword is in the document.

Intro to Computing
if '[1]' in document:
    print('Keyword found!')
Drag options to blanks, or click blank then click option'
Akeyword
Bdocument
Csearch
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'document' instead of 'keyword' inside the if condition.
2fill in blank
medium

Complete the code to add a document to the search index dictionary.

Intro to Computing
search_index['[1]'] = document_text
Drag options to blanks, or click blank then click option'
Adocument_text
Bkeyword
Cindex
Ddoc_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'keyword' as the key instead of a document ID.
3fill in blank
hard

Fix the error in the code that searches for documents containing the keyword.

Intro to Computing
for doc_id, text in search_index.items():
    if '[1]' in text:
        print(f'Document {doc_id} matches')
Drag options to blanks, or click blank then click option'
Asearch_index
Bdoc_id
Ckeyword
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if 'doc_id' is in text, which is incorrect.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length if the length is greater than 3.

Intro to Computing
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word > 3' which compares a string to a number.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their frequency if frequency is more than 1.

Intro to Computing
{ [1]: [2] for [3] in word_freq.items() if [2] > 1 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Bfreq
Cword
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'count' instead of 'freq' for frequency variable.