これまでの私のコードは次のとおりです。
# This program will determine the appropriate bonus to be given to both the store
# and the employess.
# Lab 3-4
# The main function
def main():
monthlySales = getSales() # Call to get sales
salesIncrease = getIncrease() # Call to get sales increase
storeAmount = storeBonus(monthlySales) # Call to get the store bonus
empAmount = empBonus(monthlySales) # Call to get the employee bonus
printBonus (storeAmount, empAmount) # Call to print amounts
# This function gets the monthly sales
def getSales():
monthlySales = input('Enter the monthly sales $')
monthlySales = float(monthlySales)
return monthlySales
# This function gets the percent of increase in sales
def getIncrease():
salesIncrease = input('Enter percent of sales increase. For example, 4% should be entered as 4: ')
salesIncrease = float(salesIncrease)
salesIncrease = salesIncrease / 100
return salesIncrease
# This function determines storeAmount bonus
def storeBonus(monthlySales):
if monthlySales >=110000:
storeAmount = 6000
elif monthlySales >=100000:
storeAmount = 5000
elif monthlySales >=90000:
storeAmount = 4000
elif monthlySales >=80000:
storeAmount = 3000
else:
storeAmount = 0
return storeAmount
# This function determines empAmount bonus
def empBonus(salesIncrease):
if salesIncrease >= .05:
empAmount = 75
elif salesIncrease >= .04:
empAmount = 50
elif salesIncrease >= .03:
empAmount = 40
else:
empAmount = 0
return empAmount
# This function prints the bonus information
def printBonus(storeAmount, empAmount):
print('The store bonus is $', storeAmount)
print('The employee bonus is $', empAmount)
if storeAmount == 6000 and empAmount == 75:
print('Congrats! You have reached the highest bonus amounts possible!')
# Calls main
main()
このコードをテストするために、次のシナリオを用意しました。
1) monthSales = 120500 salesIncrease = 5
2) monthSales = 93400 salesIncrease = 5
3) monthSales = 75000 salesIncrease = 1.5
4) monthSales = 82000 salesIncrease = 3.6
5) monthSales = 125000 salesIncrease = 4.5
これで 3-5 までは順調です。「従業員のボーナス額」は 75 ドルであるはずがありませんが、それは出てくるものです。この問題を解決する方法についてのアイデアはありますか? 私のコードに、私が見落としたエラーを見た人はいますか?
*編集:各入力値に対してコードが出力するはずのものは次のとおりです。
1) $6000 $75
2) $4000 $75
3) $0 $0
4) $3000 $40
5) $6000 $50