0
0
Prompt Engineering / GenAIml~10 mins

Document loading and parsing in Prompt Engineering / GenAI - Interactive Code Practice

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

Complete the code to load a text document from a file.

Prompt Engineering / GenAI
with open('document.txt', '[1]') as file:
    content = file.read()
Drag options to blanks, or click blank then click option'
Ar
Bw
Ca
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' mode which overwrites the file.
Using 'a' mode which appends to the file.
2fill in blank
medium

Complete the code to split the loaded document content into sentences.

Prompt Engineering / GenAI
sentences = content.[1]('.')
Drag options to blanks, or click blank then click option'
Ajoin
Bsplit
Creplace
Dstrip
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'join' which combines strings instead of splitting.
Using 'replace' which changes characters but does not split.
3fill in blank
hard

Fix the error in the code to parse JSON content from a document string.

Prompt Engineering / GenAI
import json
parsed_data = json.[1](content)
Drag options to blanks, or click blank then click option'
Adump
Bload
Cdumps
Dloads
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'load' which reads JSON from a file object, not a string.
Using 'dump' or 'dumps' which write JSON instead of reading.
4fill in blank
hard

Fill both blanks to create a dictionary of word counts from the document.

Prompt Engineering / GenAI
word_counts = {word: content.[1](word) for word in content.[2]()}
Drag options to blanks, or click blank then click option'
Acount
Bsplit
Clower
Dreplace
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lower' instead of 'split' to get words.
Using 'replace' which changes text but does not split or count.
5fill in blank
hard

Fill all three blanks to filter sentences containing a keyword and count them.

Prompt Engineering / GenAI
keyword = 'AI'
filtered = [sentence for sentence in content.[1]('.') if [2] in sentence.[3]()] 
count = len(filtered)
Drag options to blanks, or click blank then click option'
Asplit
Bkeyword
Clower
Dreplace
Attempts:
3 left
💡 Hint
Common Mistakes
Not converting sentences to lowercase before checking keyword.
Using 'replace' instead of 'split' to get sentences.