【问题标题】:make a calculator that calculates the volume of a cube [closed]制作一个计算立方体体积的计算器[关闭]
【发布时间】:2017-09-15 00:26:46
【问题描述】:

我是 python 新手,我的问题是当我想制作一个计算立方体体积的计算器时:

>>> print(int ** 3 (input ("Enter the side length: ")))
Enter the side length: 4
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    print(int ** 3 (input ("Enter the side length: ")))
TypeError: 'int' object is not callable

【问题讨论】:

  • int 不是 Python 中的类型。 Python 是动态类型的,因此无法定义变量类型。
  • side_len = int(input('Enter side length: ')); print('The volume of the cube is: ', side_len ** 3)

标签: python calculator cube


【解决方案1】:

int() 函数应该环绕整个 input() 函数,像这样

print(int(input('Enter the side length:')) ** 3)

【讨论】:

    猜你喜欢
    • 2013-08-09
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多