#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:不能将序列乘以'tuple'类型的非整数”是什么意思?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38175905/