#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)))