Revisión | 60bc2c6410936d9ce70295ef7a7328263a488327 (tree) |
---|---|
Tiempo | 2007-08-05 00:38:59 |
Autor | iselllo |
Commiter | iselllo |
I added object2.py which is a very simple code calculating the area of a
rectangle using classes and instantiation.
@@ -0,0 +1,17 @@ | ||
1 | +#! /usr/bin/env python | |
2 | + | |
3 | +"""square.py -- Make some noise about a square.""" | |
4 | + | |
5 | +class rectangle: | |
6 | + def __init__(self, height, width): | |
7 | + self.height = height | |
8 | + self.width = width | |
9 | + | |
10 | + def area(self): | |
11 | + return self.height * self.width | |
12 | + | |
13 | + | |
14 | +my_rect=rectangle(5.,4.) | |
15 | +print 'the width is ', my_rect.width | |
16 | +print 'the height', my_rect.height | |
17 | +print 'the area is', my_rect.area() | |
\ No newline at end of file |