作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试编写一个程序来计算池中水体积的成本(以美分为单位)一直卡在音量和回答上,无法弄清楚我做错了什么。任何帮助都会很棒。这些是我正在使用的方程式。
立方英尺的体积 = 长 * 宽 * 高
成本 = 每立方英尺成本 * 立方英尺体积
#Assignment 1, Python, Run 1
length = float(input("Please enter the length of the pool in feet:"))
width = float(input("Please input the width of the pool in feet:"))
height = float(input("Please input the height of the pool in feet:"))
cost = float(input("Please enter the cost of water in cents per cubic foot:"))
volume = [length*width*height]
answer = [cost*volume]
最佳答案
问题是您已将变量“volume”设为数组。
volume = [ something ] # This syntax says "volume is an array that contains something
您不能将一个数组乘以一个 float 并期望得到一个合理的答案。
answer = [ cost * volume ] # Here you are multiplying a float by an array
我想你的意思是
volume = length*width*height
answer = cost*volume
print("The volume is {0}, giving a total cost of {1}".format(volume, answer))
关于python - 以美分计的水量成本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25839842/
我是一名优秀的程序员,十分优秀!