Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

incrementing array value by one in python

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)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading