Home > front end >  incrementing array value by one in python
incrementing array value by one in python

Time:03-08

In the code, I need to increment "age" by one, and "age" needs to start at 24. I was thinking of making another function that would feed into def getResults and increment "age" by one from that function. Don't know how to do that. New to this. Please help. Thanks!

import pprint


def getResults():
    mylist = []
    for n in range(1, 37   1):
        currentRow = {"age": n, "numOfYears": n,
                      "beginningBalance": n, "currentSalary": 72_000.00,
                      "dividendsAndGrowth": n, "yearlyDeposit": 8_640.00,
                      "yearlyTotal": n}
        mylist.append(currentRow)

    return mylist


if __name__ == "__main__":
    z = getResults()
    pprint.pprint(z)

CodePudding user response:

Is this what you are looking for ?

import pprint


def getResults():
    mylist = []
    for n in range(1, 37   1):
        currentRow = {"age": 23 n, "numOfYears": n,
                      "beginningBalance": n, "currentSalary": 72_000.00,
                      "dividendsAndGrowth": n, "yearlyDeposit": 8_640.00,
                      "yearlyTotal": n}
        mylist.append(currentRow)

    return mylist


if __name__ == "__main__":
    z = getResults()
    pprint.pprint(z)
  • Related