Whats the problem here? Class - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Whats the problem here? Class (/thread-22770.html) |
Whats the problem here? Class - Ronaldx - Nov-26-2019 Hello, there is an error in the code, what exactly? I would use def __init__(self, openeddoor) and then self.openeddoor but I do not think this is the mistake. Thank you class Door(): def __init__(self): self.__opened = False def open(self): self.__opened = True def closeit(self): self.__opened = False def is_opened(self): return False RE: Whats the problem here? Class - buran - Nov-26-2019 explain in plain english what each method is doing. it will help to understand what the problem is RE: Whats the problem here? Class - ThomasL - Nov-26-2019 A class with a door that is always closed is not that useful ;-) RE: Whats the problem here? Class - stullis - Nov-26-2019 (Nov-26-2019, 08:21 PM)ThomasL Wrote: A class with a door that is always closed is not that useful ;-) Perhaps, but it's a safe door, no one's getting in. Not even the guy with the key. RE: Whats the problem here? Class - jefsummers - Nov-26-2019 Line 12. Return self.__opened However, that is in essence a getter. Used a lot in Java but not Python. In the code where you would call such a function just test the class instance __opened. ie front = Door() front.open() print(front.__opened)Also, note that open is a keyword and therefore should be avoided as a function name. open_door() might be a better choice. |