Room class for beginners

Aug 4th, 2021
618
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.     ''' CLASSES for beginners - simple example '''
2.
3.     class Room():
4.         def __init__(self, name, height, length, width):
5.             self.name = name
6.             self.height = height
7.             self.length = length
8.             self.width = width
9.
10.         @staticmethod
11.         def mm_to_ft(mm):
12.             return mm * 0.0032808399
13.
14.         @staticmethod
15.         def sqmm_to_sqft(sqmm):
16.             return sqmm * 1.07639e-5
17.
18.         def height_in_ft(self):
19.             return Room.mm_to_ft(self.height)
20.
21.         def width_in_ft(self):
22.             return Room.mm_to_ft(self.width)
23.
24.         def length_in_ft(self):
25.             return Room.mm_to_ft(self.length)
26.
27.         def wall_area(self):
28.             return self.length * 2 * self.height + self.width * 2 * self.height
29.
30.
31.     lounge = Room('Lounge', 1300, 4000, 2000)
32.     snug = Room('Snug', 1300, 2500, 2000)
33.
34.     print(lounge.name, lounge.height, lounge.length, lounge.length)
35.     print(snug.name, snug.height, snug.length, snug.length)
36.
37.     print(lounge.name, 'length in feet:', lounge.height_in_ft())
38.     print(f'{snug.name} wall area: {snug.wall_area()} in sq.mm., ' + \
39.           f'{snug.sqmm_to_sqft(snug.wall_area()):.2f} in sq.ft.')
40.
RAW Paste Data