forked from thecount12/rapidpythonprogramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapartment3.py
More file actions
executable file
·53 lines (44 loc) · 1.38 KB
/
apartment3.py
File metadata and controls
executable file
·53 lines (44 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
#apartment.py
# Chapter 7 Cool Features of Python
# Author: William C. Gunnells
# Rapid Python Programming
'''
required information:10 units with 2 bedrooms,
8 covered parking
1 pool, x rooms, 15 people
'''
class complex:
def __init__(self, unit, parking, pool, rooms, people):
self.unit=unit
self.parking=parking
self.pool=pool
self.rooms=rooms
self.people=people
def calc(self):
self.capacity=float(self.people)/self.rooms
self.uncovered=100-(float(self.parking)/self.people*100)
self.rooms=10*2
self.freerooms=self.rooms-self.people
def result(self):
print "The complex is at %g capacity" % self.capacity
print "There are %g percent people with uncovered parking" % self.uncovered
print "We have %g rooms" % self.rooms
print "We have %g free rooms left" % self.freerooms
myCo=complex(10,8,1,20,15)
myCo.calc() # these are tied together initialize
myCo.result() # these are tied together
#myCo.unit=10
#myCo.parking=8
#myCo.pool=1
#myCo.rooms=20
#myCo.people=15
#comment out the next two blocks
#capacity=float(myCo.people)/myCo.rooms
#uncovered=100-(float(myCo.parking)/myCo.people*100)
#myCo.rooms=10*2
#freerooms=myCo.rooms-myCo.people
#print "The complex is at %g capacity" % capacity
#print "There are %g percent people with uncovered parking" % uncovered
#print "We have %g rooms" % myCo.rooms
#print "We have %g free rooms left" % freerooms