我有这个代码来计算两个坐标之间的距离.这两个函数都在同一个类中.
但是如何在函数distToPoint中调用函数isNear?
class Coordinates:
def distToPoint(self, p):
"""
Use pythagoras to find distance
(a^2 = b^2 + c^2)
"""
...
def isNear(self, p):
distToPoint(self, p)
...
Run Code Online (Sandbox Code Playgroud) 在我的代码中,我有:
class A:
def a():
......
def b():
a()
......
b()
Run Code Online (Sandbox Code Playgroud)
然后编译器会说"NameError:未定义全局名称a()".如果我从A类中提取所有东西,那就不会有问题,但是如何在A类中定义方法呢?非常感谢你.
我目前正在使用singpath.com练习我的python,但是我遇到了一个问题:
预期的结果是:
>>>CurryPuff(3)
3.60
>>>CurryPuff(3,'Fish')
4.2
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
def CurryPuff(x,typePuff):
if(typePuff==''):
return x*1.2
if(typePuff=='Fish'):
return x*1.4
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误:
TypeError: CurryPuff() takes exactly 2 arguments (1 given)
Run Code Online (Sandbox Code Playgroud)
我曾尝试谷歌搜索,但我不是很确定使用的关键词是什么,所以希望能从这里获得帮助.
谢谢.