Skip to content

Instantly share code, notes, and snippets.

@AmosAidoo
Created October 29, 2020 12:48
Show Gist options
  • Save AmosAidoo/f594839eeed1947bc2332356c1aef314 to your computer and use it in GitHub Desktop.
Save AmosAidoo/f594839eeed1947bc2332356c1aef314 to your computer and use it in GitHub Desktop.
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
self._id = 0
def area(self):
return self.width * self.height
def perimeter(self):
return 2*self.width + 2*self.height
@property
def id(self):
return self._id
@id.setter
def id(self, id):
self._id = id
if __name__ == '__main__':
store = []
while 1:
print("1. Create new rectangle")
print("2. Display an already stored rectangle")
print("3. Quit")
inp = int(input())
if inp == 1:
w, h = map(int, input().split(" "))
rect = Rectangle(w, h)
rect.id = len(store)+1
print(f"The id is {rect.id}")
store.append(rect)
elif inp == 2:
print("Which rectangle?", list(range(1, len(store)+1)))
inp = int(input())
if inp < 0 or inp > len(store):
print("Invalid id")
rect = store[inp-1]
print("Unique Number", rect.id)
print("Sides", rect.width, rect.height)
print("Area", rect.area())
print("Perimeter", rect.perimeter())
print()
elif inp == 3:
print("Quitting...")
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment