i got a error saing: unsupported operand type(s) for +=: 'int' and 'tuple'

    def accounting(self):
        [total], = self.db.c.execute('''SELECT NeedInvestment FROM building WHERE id == 5''')

        investment = []
        for i in self.db.c.execute('''SELECT AmountOfInvestment FROM investor '''):
            investment.append(i)

        totaltemp = 0

        while totaltemp <= total:
            i = random.randint(0, 5)
            totaltemp += investment[1]

How do i correct it?

1 Answers

1
DroidX86 On
self.db.c.execute('''SELECT AmountOfInvestment FROM investor ''')

this returns a list of tuple objects.

totaltemp += investment[1]

investment[1] is the second tuple in the list. It's a tuple. totalTemp is an int as declared here:

totalTemp = 0

So you're trying to add a tuple to an int - which is not defined in the python language.

You probably want to access a value inside the tuple like this:

totalTemp = investment[0][1]