Python Forum
Whats the problem here? Class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Whats the problem here? Class
#1
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
Reply
#2
explain in plain english what each method is doing. it will help to understand what the problem is
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
A class with a door that is always closed is not that useful ;-)
Reply
#4
(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.
Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Whats the difference between these two? Puxk 4 3,337 Jul-08-2020, 06:02 PM
Last Post: stullis
  whats wrong with my code? syntax errors r6lay 5 6,407 Mar-16-2017, 04:14 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020