Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to assign a string to the variable.
Python
message = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string.
Using a number instead of a string.
✗ Incorrect
The variable message is assigned a string value using quotes.
2fill in blank
mediumComplete the code to change the variable type from int to float.
Python
number = 10 number = [1](number)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
str() which converts to text, not a number.Using
bool() which converts to True or False.✗ Incorrect
The float() function converts an integer to a floating-point number.
3fill in blank
hardFix the error by completing the code to add a number to a string correctly.
Python
age = 30 message = "I am " + [1] + " years old."
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to add an integer directly to a string causes an error.
Using
int() or float() does not convert to string.✗ Incorrect
You must convert the number age to a string before adding it to another string.
4fill in blank
hardFill both blanks to create a list of squares for numbers greater than 3.
Python
squares = [x[1]2 for x in range(1, 6) if x [2] 3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
+ instead of power operator.Using
< instead of > for filtering.✗ Incorrect
The ** operator is used for power, and > filters numbers greater than 3.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase keys and values greater than 0.
Python
result = {{ [1] }}: [2] for [3], v in data.items() if v > 0} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names like
item.Not converting keys to uppercase.
✗ Incorrect
Keys are converted to uppercase with k.upper(), values are v, and k is the key variable.