You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Zybooks Python第二章挑战题:墙面刷漆油漆量计算求解

Paint Calculation Fix for Zybooks Python Challenge

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_area is 250.0, so it calculates 250.0 / 350 which gives the right amount for that case.
  • When test 2 runs, wall_area becomes 578.6, so it automatically uses that value to compute 578.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

火山引擎 最新活动