Python Forum
Calculate AGE in years
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculate AGE in years
#6
When you subclass and the superclass has an __init__ method, the subclass needs to call the __init__ method for the superclass. The best way to do that is use super().
class Docent(persoon):
    def __init__(self, naam, sekse, geboortedatum,*Salaris):
        super().__init__(naam, seksa, geboortedatum)
        if(Salaris==None):
            self.Salaris = "0"
        else:
            self.Salaris = Salaris
You are not handling the optional Salaris argument correctly.
class Docent(persoon):
    def __init__(self, naam, sekse, geboortedatum, Salaris=0):
        super().__init__(naam, seksa, geboortedatum)
        self.Salaris = Salaris
Your __init__() method made Python think Solaris was a list of positional arguments following geboortedatum when what you really want is an argument where the user has to option of providing an argument value, or using the default value.
Reply


Messages In This Thread
Calculate AGE in years - by Kessie1971 - Apr-24-2023, 07:31 AM
RE: Calculate AGE in years - by DeaD_EyE - Apr-24-2023, 09:46 AM
RE: Calculate AGE in years - by Kessie1971 - Apr-24-2023, 05:07 PM
RE: Calculate AGE in years - by DeaD_EyE - Apr-24-2023, 05:28 PM
RE: Calculate AGE in years - by Kessie1971 - Apr-24-2023, 06:05 PM
RE: Calculate AGE in years - by deanhystad - Apr-24-2023, 06:22 PM
RE: Calculate AGE in years - by Kessie1971 - Apr-24-2023, 06:36 PM
RE: Calculate AGE in years - by deanhystad - Apr-24-2023, 07:20 PM
RE: Calculate AGE in years - by Kessie1971 - Apr-24-2023, 07:23 PM
RE: Calculate AGE in years - by buran - Apr-25-2023, 06:35 AM
RE: Calculate AGE in years - by DeaD_EyE - Apr-25-2023, 08:37 AM
RE: Calculate AGE in years - by buran - Apr-25-2023, 08:55 AM
RE: Calculate AGE in years - by Kessie1971 - Apr-25-2023, 05:00 PM
RE: Calculate AGE in years - by deanhystad - Apr-25-2023, 05:33 PM
RE: Calculate AGE in years - by Kessie1971 - Apr-25-2023, 05:44 PM
RE: Calculate AGE in years - by Kessie1971 - Apr-25-2023, 05:56 PM
RE: Calculate AGE in years - by deanhystad - Apr-25-2023, 07:15 PM
RE: Calculate AGE in years - by deanhystad - Apr-26-2023, 03:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tracking leap.py years for gregorian calendar (Exercism org) Drone4four 11 3,985 Oct-14-2022, 03:20 PM
Last Post: betinajessen
  Problem with code to calculate weekday for leap years! Event 2 2,937 Dec-15-2018, 05:13 PM
Last Post: Event
  python age calculator need to find the number of years before they turn 100 not using orangevalley 4 10,117 Mar-26-2018, 04:44 AM
Last Post: PyMan
  human years to dog years jhall710 7 11,614 May-08-2017, 05:57 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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