-5

Here is my code so far:

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

Now in order to test this code I was give these following scenarios:

1) monthlySales = 120500 salesIncrease = 5

2) monthlySales = 93400 salesIncrease = 5

3) monthlySales = 75000 salesIncrease = 1.5

4) monthlySales = 82000 salesIncrease = 3.6

5) monthlySales = 125000 salesIncrease = 4.5

Now all is well up until 3-5. The "employee bonus amount" is not supposed to be $75, however that is what comes out. Any ideas on how to fix this problem? Anyone see any errors in my code that I failed to see?

*Edit: What the code is supposed to output for each input value is as follows;

1) $ 6000 $ 75

2) $ 4000 $ 75

3) $ 0 $ 0

4) $ 3000 $ 40

5) $ 6000 $ 50

4

1 回答 1

6

It's hard to tell what your problem is because your question doesn't explain what you are trying to do but I would hazard a guess that you're off by a factor of 100:

def empBonus(salesIncrease):
    if salesIncrease >= 5:
        empAmount = 75
    elif salesIncrease >= 4:
        empAmount = 50
    elif salesIncrease >= 3:
        empAmount = 40
    else:
        empAmount = 0
    return empAmount

To use your third example, you were checking 1.5 >= 0.05 which is of course True so empAmount was being set to 75.

于 2012-07-15T01:22:07.070 回答