gpt4 book ai didi

python - "TypeError: can' t 将序列乘以 'tuple' 类型的非整数是什么意思?

转载 作者:太空宇宙 更新时间:2023-11-04 08:48:08 25 4
gpt4 key购买 nike

#Finding the volume of a box
print("Welcome to box volume calculation! Please answer the following questions.")
x = float(raw_input("How wide is the box? ")),
y = float(raw_input("How high is the box? ")),
z = float(raw_input("How long is the box? ")),

"The volume of the box is " + str(x*y*z) + " units cubed."

我收到的错误消息:

Traceback (most recent call last):
File "C:\Python25\Scripts\Randomness.py", line 22, in <module>
"The volume of the box is " + str(x*y*z) + " units cubed."
TypeError: can't multiply sequence by non-int of type 'tuple'

最佳答案

去掉要求输入的行中的逗号。这些行应该是:

x = float(raw_input("How wide is the box? "))
y = float(raw_input("How high is the box? "))
z = float(raw_input("How long is the box? "))

解释......形式的陈述:

x = a, b, c

创建一个包含三个元素的元组,同样地:

x = a,

创建一个包含一个 元素的元组。所以在这里,声明如下:

x = float(raw_input(...)),

创建一个元素的元组,该元素是您的输入!

关于python - "TypeError: can' t 将序列乘以 'tuple' 类型的非整数是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38175905/

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