gpt4 book ai didi

python - 以美分计的水量成本

转载 作者:行者123 更新时间:2023-11-28 17:39:55 25 4
gpt4 key购买 nike

尝试编写一个程序来计算池中水体积的成本(以美分为单位)一直卡在音量和回答上,无法弄清楚我做错了什么。任何帮助都会很棒。这些是我正在使用的方程式。

立方英尺的体积 = 长 * 宽 * 高
成本 = 每立方英尺成本 * 立方英尺体积

#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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com