所以我试着做一个程序,要求3个数字,然后返回这些数字的乘积(确定一个长方体的体积)
def cuboid ():
A = input('Height '),
B = input('Width '),
C = input('Depth '),
到目前为止,这使得PYthon需要这三个值,但是我不知道如何告诉PYthon它们不是字符串,而是整数。i、 我不知道如何使用int()
命令。
如果在那之后我输入:Volume = A*B*C
,它会给出一个类型错误,因为他认为1,2和3不是整数。你知道吗
我不知道为什么这样不行,因为
def o3 (x,y,z):
print x*y*z
确实有效。 提前谢谢
这就是你想要的吗?你知道吗
您使用的是
input()
,而您应该使用raw_input()
。在输入之后,您只需要说a = int(a)
,a将是一个整数,您可以对它进行普通的算术运算。你知道吗示例:
相关问题 更多 >
编程相关推荐