How do I find the total in an object?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jackwaters
    New Member
    • Jul 2010
    • 5

    How do I find the total in an object?

    I am building a music store example in python. I am trying to find a way of displaying the total of all of the sales of all of the music.

    Everything is stored in objects in a list trackList. Track is the object so track.sales returns the sales of particular track.

    This is what I have so far:

    Code:
    def totalSales(trackList):
        for track in trackList:
            total = sum(track.sales)
        print total
    I'm really struggling so any help would be great.
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    Code:
    def totalSales(trackList):
        total=0
        for track in trackList:
            total += track.sales
        print total

    Comment

    • Jackwaters
      New Member
      • Jul 2010
      • 5

      #3
      Thanks, works perfectly.

      Comment

      Working...