0
0
Prompt Engineering / GenAIml~10 mins

Cost optimization in Prompt Engineering / GenAI - Interactive Code Practice

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

Complete 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'
A*
B/
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' will add costs instead of multiplying.
Using '/' or '-' will give incorrect total cost.
2fill in blank
medium

Complete 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'
A/
B+
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '*' will not compute average correctly.
Using '-' will give wrong result.
3fill in blank
hard

Fix 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'
Asum
Bmax
Cmin
Dlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using max() returns the highest cost, not the lowest.
Using sum() or len() are unrelated.
4fill in blank
hard

Fill 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'
A<
B>
C100
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' will select expensive items, not affordable ones.
Using 50 instead of 100 changes the threshold.
5fill in blank
hard

Fill 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'
Aitem.upper()
Bcost
Citem
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'price' instead of 'cost' causes undefined variable error.
Not using uppercase for keys misses the requirement.