#Hoofdstuk 15 Klassen en objecten
#15.1 Eigen gedefinieerde typen
class Punt(object):
"""vertegenwoordigd een punt in een 2-D omgeving"""
print Punt
blanco = Punt()
print blanco
blanco.x = 3.0
blanco.y = 4.0
print blanco.y
x = blanco.x
print x
print '(%g, %g)' % (blanco.x, blanco.y)
afstand= math.sqrt(blanco.x**2 + blanco.y**2) # zie comment hieronder
def print_punt(p):
print '(%g, %g)' % (p.x, p.y)
print_punt(blanco)
#<class '__main__.Punt'>
#<__main__.Punt object at 0x949358c>
#4.0
#3.0
#(3, 4) !!!!!!!!!!!! Opgelet !!!!!!!! in tekst staat (3.0, 4.0)
#
#Traceback (most recent call last):
# File "/home/hendrikus/bin/class_01.py", line 19, in <module>
# afstand= math.sqrt(blanco.x**2 + blanco.y**2)
#NameError: name 'math' is not defined
#
#ook deze regel uit orginale tekst think_python klopt niet:
#
#distance = math.sqrt(blank.x**2 + blank.y**2)
#Traceback (most recent call last):
# File "/home/hendrikus/bin/class_01.py", line 19, in <module>
# distance = math.sqrt(blank.x**2 + blank.y**2)
#NameError: name 'math' is not defined