Zybooks Python第二章挑战题:墙面刷漆油漆量计算求解
Hey there! I see exactly where you're stuck here. The issue with your initial attempts is that you're using hardcoded numbers like 250 or 578.6 instead of referencing the variable wall_area that's already defined in the template.
Since the problem states that 350 square feet requires 1 gallon of paint, the formula you need is straightforward: divide the total wall area by 350. And because wall_area is a variable that changes between test cases (250.0 for test 1, 578.6 for test 2), you need to use that variable in your calculation instead of a fixed number.
Here's the correct code to replace the ''' Your solution goes here ''' section:
gallons_paint = wall_area / 350
Let me break this down:
- When test 1 runs,
wall_areais 250.0, so it calculates250.0 / 350which gives the right amount for that case. - When test 2 runs,
wall_areabecomes 578.6, so it automatically uses that value to compute578.6 / 350—no need to change anything in your code!
Since you haven't learned conditional statements yet, this is the perfect solution because it's a simple, reusable calculation that works for any value of wall_area the test cases throw at you.
内容的提问来源于stack exchange,提问作者negru08




