Python Forum
function not giving back total
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function not giving back total
#2
Python does not support polymorphism based on the signature. Each time you you use the same name for a method it replaces the previous method declaration.
    def total(self):  # This method is thrown away because of the method below.
        return self.__total
 
    def total(self, newtotal):  # This method replaces the total method defined above
        self.__total = newtotal
I think you want to use properties.

https://docs.python.org/3.8/library/func...l#property

The total field is 0 because you initialize total to zero and never change it. I would not make total a variable in class because it can be calculated from hours and hourly wage. If you want to have a total in Pay you'll have to compute total each time hours or pay rate is changed.
Reply


Messages In This Thread
function not giving back total - by SephMon - Aug-25-2020, 11:42 AM
RE: function not giving back total - by deanhystad - Aug-25-2020, 12:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The function of double underscore back and front in a class function name? Pedroski55 9 645 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  The formula in the function is not giving the correct value quest 1 1,237 Mar-30-2022, 03:20 AM
Last Post: quest
  Struggling for the past hour to define function and call it back godlyredwall 2 2,216 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  Get multiple values from function and total it. nirlep 5 3,223 Feb-05-2019, 06:54 AM
Last Post: nirlep

Forum Jump:

User Panel Messages

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