1

#End of Year Bonus Calculation WITH FUNCTION #modify the computer program provided so that the calculation of the bonus is done by a function whose input data (its parameters)are the employee’s total sales for the year and the employee’s years of service. Your function must calculate and return the employee’s total bonus for the year using the same decision logic used in the provided program code. This function must be called from the main program which must first prompt the user to enter the total sales for the year and the number of years with the company, which need to be used as the arguments of the function call. Finally, the main program must report to the user the value for the total bonus returned by the function. When executed, this new version of the bonus calculation program must produce exactly the same results as those produced by the original code provided. #function definition:

--- the signature(header)

def yearlyBonus(yearSales, yearsOfService):
    #Calculate monthly average sales 
    monthlyAveSales = yearSales / 12
    #Decide bonus based on monthly sales average
    if monthlyAveSales < 1000:
        salesBonus = 100
    elif monthlyAveSales >= 1000 and monthlyAveSales < 2000:
        salesBonus = 200
    elif monthlyAveSales >= 2000 and monthlyAveSales < 3000:
        salesBonus = 300
    else:
        salesBonus = 400
    return(salesBonus)
#
#
#Main Program 
#Prompt user to enter basic data
yearSales = float(input('Enter the total sales for the year: '))
yearsOfService = int(input('Enter the number of years with the company: '))
#Calculate the yearly bonus by adjusting the sales bonus
#per years of service:
#if years of service is 10 or more,
#increase the sales bonus by the appropriate percent
if yearsOfService >= 20:
    yearlyBonus = salesBonus * 1.20
elif yearsOfService >= 10:
    yearlyBonus = salesBonus * 1.10
else:
    yearlyBonus = salesBonus
#Report yearly bonus
print('The bonus for the year is {0:.2f}.'.format(yearlyBonus(yearSales, yearsOfService)))
Jeffrey23
  • 11
  • 1

1 Answers1

0

you need to set salesBonus = yearlyBonus(yearSales, yearsOfService) in the main before the if..else. or better try and recode because it is a bit confused

jahnLudvik
  • 29
  • 6
  • Thank you so much! I added your suggestion and the error went away! However, there is a new error present now: line 38, in print('The bonus for the year is {0:.2f}.'.format(yearlyBonus(yearSales, yearsOfService))) TypeError: 'float' object is not callable – Jeffrey23 Apr 27 '21 at 02:19
  • Do you know what this means? – Jeffrey23 Apr 27 '21 at 02:19
  • if it works please accept the answer with the tick... try with the same function at the end of the if else and than call it in format. actually it s quite confusing your code – jahnLudvik Apr 27 '21 at 02:25