Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to convert the text to lowercase.
NLP
text = "Hello World!" lower_text = text.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using upper() instead of lower()
Using capitalize() which only changes the first letter
✗ Incorrect
The lower() method converts all characters in a string to lowercase.
2fill in blank
mediumComplete the code to remove leading and trailing spaces from the text.
NLP
text = " Hello World! " clean_text = text.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using split() which splits the string into words
Using replace() which replaces characters inside the string
✗ Incorrect
The strip() method removes spaces from the start and end of a string.
3fill in blank
hardFix the error in the code to normalize the text by removing punctuation.
NLP
import string text = "Hello, World!" normalized = text.translate(str.maketrans('', '', [1]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string.whitespace which removes spaces instead
Using string.ascii_letters which removes letters
✗ Incorrect
string.punctuation contains all punctuation characters to remove from the text.
4fill in blank
hardFill both blanks to create a dictionary that maps words to their lowercase forms, filtering out words shorter than 4 letters.
NLP
words = ["Apple", "is", "Good", "for", "You"] lower_map = {word[1]: word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .upper() instead of .lower()
Using '>=' instead of '>' which changes the filter condition
✗ Incorrect
We use .lower() to convert words to lowercase and '>' to filter words longer than 3 letters.
5fill in blank
hardFill all three blanks to create a normalized frequency dictionary of lowercase words longer than 2 letters.
NLP
texts = ["Hello", "world", "HELLO", "test"] freq = {} for word in texts: w = word[1] if len(w) [2] 2: freq[w] = freq.get(w, 0) [3] 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' or '*' instead of '+' for counting
Using '>=' instead of '>' changing the filter
✗ Incorrect
We lowercase words, filter length > 2, and add 1 to frequency count.