#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(...)),
创建一个元素的元组,该元素是您的输入!
