[Python] How to calculate and add increased pay in a list

Discussão em 'Python' iniciado por Stack, Julho 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a simple block of code that contains a list of salaries and the goal is to calculate a percentage increase (in this case it's 4%) and end up with the new salary listed with the increased pay. I'm able to calculate the percentage just fine, but I'm stuck trying to figure out how to add this increase to the existing pay in a list.

    Here's the code I have so far. I can figure out how to get the result I want on a single expression with one number, I'm just strugging to apply it to a list.

    def employee_salary():
    salary_increase = [.04 * n for n in [4100.25,
    4025.75,
    5200.00,
    3330.25,
    4420.50,
    2900.25,
    3210.00,
    6322.00,
    1125.00,
    1460.00]]

    print(salary_increase)


    employee_salary()

    [164.01, 161.03, 208.0, 133.21, 176.82, 116.01, 128.4, 252.88, 45.0, 58.4]


    What I want from here is to add these percentage results to the old salary to produce the new. While I'm new to Python and programming in general, I feel like the answer is likely pretty simple. But my tired brain can't seem to see it.

    Appreciate the help!

    Continue reading...

Compartilhe esta Página