-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapartment4.py
More file actions
executable file
·39 lines (34 loc) · 1008 Bytes
/
apartment4.py
File metadata and controls
executable file
·39 lines (34 loc) · 1008 Bytes
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
#!/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):
a="The complex is at %g capacity" % self.capacity
b="There are %g percent people with uncovered parking" % self.uncovered
c="We have %g rooms" % self.rooms
d="We have %g free rooms left" % self.freerooms
data=[a,b,c,d]
return data
if __name__=="__main__":
myCo=complex(10,8,1,20,15)
myCo.calc() # these are tied together initialize
for i in myCo.result(): # these are tied together
print i