0

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()
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by vlady
0

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.

Edited by pyTony: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.