Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python question
#1
Hello! I am a beginner and I need help. What's the problem with this syntex? Thanks for the help

class Alma

    def __init__(x):

        self.x = x

    def count(self,x):

        self.x = x+1

class ZoldAlma:

    def __init__(self, y=0):

        Alma.__init__(self, 3)

        self.y = y

    def count(self):

        self.y += 1     

def main():

    obj = ZoldAlma()

    obj.count()

    print(obj.x, obj.y)

main()
Reply
#2
In Alma __init__ needs self as the first argument
In ZoldAlma the call to Alma should be self.somevar = Alma(3)
ZoldAlma does not have x. If you changed the code as above, then obj.somevar.x can be referenced and printed.
Reply


Forum Jump:

User Panel Messages

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