runtime
332 / 500
question 332 Functional & Dynamic Python · easy

The portion calculator that breaks the product page

per_portion(nutriments, grams) converts per-100 g values to a portion. Two bugs were reported: every 30 g portion shows 0, and after a portion is shown, the product page's per-100 g values are wrong. Fix it so it returns a new dictionary and leaves its argument alone.

Functionper_portion(nutriments, grams)
Returnsa new dictionary with the same keys, each value value * grams / 100
Must notchange nutriments
Examples
callper_portion({'sugars_100g': 25, 'salt_100g': 0.49}, 30)returns{'sugars_100g': 7.5, 'salt_100g': 0.147}
callper_portion({'fiber_100g': 10}, 40)returns{'fiber_100g': 4.0}
callper_portion({'sugars_100g': 1}, 100)returns{'sugars_100g': 1.0}

Loading your progress…

The portion calculator that breaks the product page — Python practice · Runtime