Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to calculate the total cost by multiplying unit cost and quantity.
Prompt Engineering / GenAI
total_cost = unit_cost [1] quantity Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' will add costs instead of multiplying.
Using '/' or '-' will give incorrect total cost.
✗ Incorrect
Multiplying unit cost by quantity gives the total cost.
2fill in blank
mediumComplete the code to calculate the average cost from a list of costs.
Prompt Engineering / GenAI
average_cost = sum(costs) [1] len(costs)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '*' will not compute average correctly.
Using '-' will give wrong result.
✗ Incorrect
Average is total sum divided by number of items.
3fill in blank
hardFix the error in the code to select the minimum cost from a list.
Prompt Engineering / GenAI
min_cost = [1](cost_list) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
max() returns the highest cost, not the lowest.Using
sum() or len() are unrelated.✗ Incorrect
The min() function returns the smallest value in a list.
4fill in blank
hardFill both blanks to create a dictionary of item costs only if cost is less than 100.
Prompt Engineering / GenAI
affordable_items = {item: cost for item, cost in items.items() if cost [1] [2] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' will select expensive items, not affordable ones.
Using 50 instead of 100 changes the threshold.
✗ Incorrect
The dictionary comprehension filters items with cost less than 100.
5fill in blank
hardFill all three blanks to create a dictionary of item names in uppercase with costs greater than 20.
Prompt Engineering / GenAI
filtered = { [1]: [2] for [3], [2] in data.items() if [2] > 20 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'price' instead of 'cost' causes undefined variable error.
Not using uppercase for keys misses the requirement.
✗ Incorrect
The dictionary comprehension uses uppercase item names as keys and costs as values, filtering costs above 20.