Hello,

I am learning classes and object and I have a problem with this code. Simply does not work. Can you tell me the reason please? Error message tells me that Distance is not defined...(I donĀ“t understand this message)

Thank you for help!

Vlady

class Distance(object):
    'return distance between 2 points'
    point=Distance()
    point.x=3.0
    point.y=4.0
    print_distance(point)

def print_distance(d):
    distance = math.sqrt(d.x**2 + d.y**2)
    print distance

def main():
    pass

if __name__ == '__main__':
    main()

You have everything wrong, study more, and start fresh when you understand basics. I would consider making distance a method of Point class. Repeat especialy these:__init__ method and self parameter.

You are very helpful MR TONY!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.