Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a wearable device's main function.
Intro to Computing
def wearable_device(): return [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string.
Returning a number instead of a string.
✗ Incorrect
The function should return a string describing the device. Strings must be in quotes.
2fill in blank
mediumComplete the code to check if a wearable device is active.
Intro to Computing
is_active = [1] if is_active: print("Device is on")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "yes" instead of the boolean True.
Using lowercase true or false which are not valid in Python.
✗ Incorrect
Boolean True means the device is active. It must be capitalized in Python.
3fill in blank
hardFix the error in the code to correctly calculate battery percentage.
Intro to Computing
battery_level = 80 max_battery = 100 percentage = battery_level [1] max_battery * 100 print(percentage)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or subtraction instead of division.
Multiplying battery_level by max_battery directly.
✗ Incorrect
To find the percentage, divide battery_level by max_battery, then multiply by 100.
4fill in blank
hardFill both blanks to create a dictionary of wearable devices and their battery levels.
Intro to Computing
devices = {"watch": [1], "earbuds": [2] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings like "active" instead of numbers.
Mixing numbers and strings incorrectly.
✗ Incorrect
Battery levels are numbers, so use 85 and 90 without quotes.
5fill in blank
hardFill both blanks to filter devices with battery above 50%.
Intro to Computing
filtered = {k: v for k, v in devices.items() if v [1] [2]
print(filtered)
# Expected output: {'watch': 85, 'earbuds': 90} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than or equal instead of greater than.
Using equality instead of comparison.
✗ Incorrect
The code filters devices where battery level (v) is greater than 50.