Need to make my salary schedule into functions

Viewed 30
def main():
    startingSalary = int(input("Please enter your Starting Salary: "))
    yearsofExperience = int(input("Please enter your YOE: "))
    percentIncrease = float(input("Enter 0.02: "))


def calculations(main):
    for yearsofExperience in range(1,yearsofExperience + 1):
        startingSalary = startingSalary + startingSalary * percentIncrease

def display(calculations):
    return(yearsofExperience,format(startingSalary, '.2f'))

main()
display(calculations)

I have tried many combinations, and cannot figure out how to fix this.

Traceback (most recent call last): File "/Users/frank/Documents/SalarySchedule.py", line 42, in display(main, calculations) File "/Users/frank/Documents/SalarySchedule.py", line 38, in display return(yearsofExperience,format(startingSalary, '.2f')) NameError: global name 'yearsofExperience' is not defined

This is the error I get, I don't understand how it is not defined when I pass it from the main function. The program runs the inputs, and then when it's supposed to print out the tabular form it just fails. This program works without functions, but I'm trying to get better with them and use functions for this.

My plan is to have the user enter what is needed into main, then pass that into the calculations function which will do the math based on the years of experience they input, but as I said, it gives me this error because it's not defined somehow?

0 Answers
Related