0
0
Pythonprogramming~10 mins

Why strings are used in Python - Test Your Understanding

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

Complete the code to create a string variable named greeting with the value 'Hello'.

Python
greeting = [1]
Drag options to blanks, or click blank then click option'
A"Hello"
B123
CHello
DTrue
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting to use quotes around the text.
Using a number or boolean instead of text.
2fill in blank
medium

Complete the code to print the string stored in the variable message.

Python
message = "Welcome"
print([1])
Drag options to blanks, or click blank then click option'
Amessage
Bprint
C"message"
DWelcome
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Putting quotes around the variable name, which prints the name itself.
Trying to print the text directly without using the variable.
3fill in blank
hard

Fix the error in the code to concatenate two strings stored in variables first and last.

Python
first = "John"
last = "Doe"
full_name = first [1] last
print(full_name)
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using arithmetic operators like - or * which cause errors with strings.
Forgetting to use an operator between the variables.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values.

Python
words = ["apple", "bat", "car"]
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 as the dictionary value.
Using < instead of > which changes the filter condition.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values for words longer than 2 letters.

Python
words = ["dog", "cat", "a"]
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 w instead of w.upper() for keys.
Using < instead of > which changes the filter.
Using w instead of len(w) for values.