Python Forum
Calculate AGE in years
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculate AGE in years
#8
Read the error message carefully. There is no Docent.verhoogSalaris() method.

Don't do this:
  def isMan(self):
    if self.sekse == "M":
      return True
    else:
      return False   
Do this:
  def isMan(self):
    return self.sekse == "M"
Think about how to solve the problem. Think about how to translate the solution to code. When the code is written, review and think about your code. In this case, you have a comparison that returns True or False. Does it make sense to check if the comparison is True and then return True? The if-else is extra code. Don't write extra code.

I don't like this either:
    def setSalaris(self, SalarisInput):
      self.Salaris = SalarisInput
Why did you write this? The user can access the attribute directly. What is added by writing this extra code?

Your age calculation is wrong. If I was born July 6, 2000, am I 23 years old today (April 24, 2023)? Your code says I am. I don't agree. Look at DeaD_EyE's year calculation that takes month and day into account.
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,914 Oct-14-2022, 03:20 PM
Last Post: betinajessen
  Problem with code to calculate weekday for leap years! Event 2 2,890 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,055 Mar-26-2018, 04:44 AM
Last Post: PyMan
  human years to dog years jhall710 7 11,525 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