全局找不到Jython / Python名称

时间:2015-03-08 11:10:03

标签: python jython

请帮助我,我收到了这个错误:

diagonal Name not found globally.
A local or global name could not be found. You need to define the function or variable before you try to use it in any way.

您是否也可以帮助我如何使用print.now()并显示三个变量。 感谢

 def computeSquareFeatures(p):

  p = input("Enter square side length:")
  area = p*p
  perimeter = p*4
  diagonal = math.sqrt(2*(p**2))

  print.Now("Area is %d, Perimeter is %d, Diagonal length is %d") % area, perimeter, diagonal

computeSquareFeatures(p)

1 个答案:

答案 0 :(得分:0)

你正在传递p,但在你做之前没有宣布:

computeSquareFeatures(p)

您在函数内使用p设置input

您还需要在函数内部使p成为一个int,否则您的区域计算将无法按照您的想法执行,确保您已导入数学并且print.Now似乎也不正确。< / p>

工作职能的一个例子:

import math
# removed p as you are taking getting it as input
def computeSquareFeatures():
  p = int(raw_input("Enter square side length: "))
  area = p*p
  perimeter = p*4
  diagonal = math.sqrt(2*(p**2))
  print("Area is %d, Perimeter is %d, Diagonal length is %d") %(area, perimeter, diagonal)

computeSquareFeatures()

它的工作原理如下:

$jython jt.py
Enter square side length:33
Area is 1089, Perimeter is 132, Diagonal length is 46