Question

In: Computer Science

Homework 3 Loop and Function (PYTHON) You are asked to develop a compensation calculator application for...

Homework 3 Loop and Function (PYTHON)

You are asked to develop a compensation calculator application for a department store. At the department store, the compensation of sales staff consists of a base salary and a commission. The base salary is $5,000, and the commission rate is tiered based on sales amount as following:

Sales AmountCommission Rate

$0.01 – $5,000 8%

$5,000.01 – $10,000 10%

$10,000.01 and above12%

For example, if the sales amount is $12,000, the commission is calculated as following: commission = $5,000 * 8% + ($10,000 - $5,000) * 10% + ($12,000 - $10,000) * 12%. You can start with a few specific amounts first to help you figure out the general representation for commission calculation

Requirements: (1) Define compute_commission function that computes the commission, using the above commission scheme. This function receives one parameter representing the sales amount and returns the corresponding commission.

(2) Define a print_commission function, which receives three parameters representing the beginning sales amount, sales increment, and ending sales amounts, and has no return. This function uses a for-loop to display a sales and commission table. For example, if the beginning sales amount is 10000, sales increment is 5000, and the ending sales amount is 100000, then this function will print out the following table:

Sales Amount    Commission

10000                900.0

15000               1500.0

...

95000               11100.0

100000             11700.0

Note: this function must call the compute_commission function to determine the commission column.

(3) Next, define a target_sales function, which receives one parameter representing a desired salary and returns the corresponding sales amount that generates the desired salary. For example, if a staff’s desired salary is 30000 (which consists of base salary + commission), then this function will return a sales amount of 210834, which is the minimum sales amount that the staff must generate to earn the desired 30000 salaries.

Note: this function must use a while-loop,and it must call the compute_commission function whenever you want to calculate the commission.In addition, it must start with an initial sales amount of $1 and increases the sales amount only by $1 in each iteration until it finds the sales amount needed to generate the desired salary.

(4) Define the main function, which will call the print_commission function to display a sales-commission table with 10000 as the beginning sales amount, 5000 as the sales increment, and 100000 as the ending sales amount. Then, ask users to enter their desired salary and use it as the argument to call the target_sales function. Lastly, display a message informing user the sales amount needed for the desired salary.

(5) Call the main function. Fix any syntax errors and test your code if you can. Save your file (especially if you can’t run it). Submit the python file through Canvas for grading. Check the rubric on Canvas.

Homework 3 Loop and Function (PYTHON)

Solutions

Expert Solution

#method to compute commission
def compute_commission(sales_amount):

    #return comissions based on the criterion given based on sales amount
    if sales_amount > 0.01 and sales_amount <= 5000:
        return 0.8*sales_amount
    elif sales_amount > 5000 and sales_amount <= 10000:
        return 400 + (sales_amount - 5000) * 0.10
    elif sales_amount > 10000:
        return 400 + 500 + (sales_amount - 10000)*0.12


#method to print comission table
def print_commission(begin, incr, end):
    print("\tSales Comission Table\n")
    print("Sales Amount\t\tCommision")

    #for loop to print comission table
    for s in range(begin, end, incr):
        commission = compute_commission(s)
        print("   " + str(s) + "  \t\t  " + str(commission))


#method to compute target sales
def target_sales(desired_salary):
    needed_sales_amt = 1
    
    while (5000 + compute_commission(needed_sales_amt) < desired_salary):
        needed_sales_amt = needed_sales_amt + 1
    return needed_sales_amt

#main method
def main():
    print_commission(10000, 5000, 105000)

    #read user input for desired salary
    desired_salary = int(input("\nEnter the desired salary: "))
    print(desired_salary)

    #calculate the sales amout needed for the desired salary
    sales_amount = target_sales(desired_salary)

    #display the needed sales amount
    print("\nNeeded sale of amount " + str(sales_amount))

if __name__ == "__main__":
    main()

You can refer this screenshot of the code if you have any problem with indentation in above code

Output:

if it helps you, do upvote as it motivates us a lot!


Related Solutions

Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of...
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of a number. * function name: get_fact * parameters: num (int) * returns: int * operation: Must use a loop here. Essentially calculate and return the factorial of whatever number is provided. but: - If num is less than 1 or greater than 20, print "num is out of range" and exit the function - If num is not an int, print "invalid num parameter"...
Loop invariants: Consider the following Python function that merges two sorted lists. Here is a loop...
Loop invariants: Consider the following Python function that merges two sorted lists. Here is a loop invariant for loop 1: “the contents ofnewlistare in sorted order,newlistcontainsaelements oflistAandbelements oflistB” def mergeSortedLists(listA, listB):  newlist = [ ]  a = 0  b = 0  # loop 1  while a < len(listA) and b < len(listB):   if listA[a] < listB[b]:    newlist.append(listA[a])    a +=1   else:    newlist.append(listB[b])    b +=1  if a < len(listA):   newlist.extend(listA[a:])  if b < len(listB):   newlist.extend(listB[b:])  return newlist (a) Write down (in regular...
Java-- For this homework you are required to implement a change calculator that will provide the...
Java-- For this homework you are required to implement a change calculator that will provide the change in the least amount of bills/coins. The application needs to start by asking the user about the purchase amount and the paid amount and then display the change as follows: Supposing the purchase amount is $4.34 and the paid amount is $20, the change should be: 1 x $10 bill 1 x $5 bill 2 x Quarter coin 1 x Dime coin 1...
Python Write a for loop with a range function and format output as currency Use an...
Python Write a for loop with a range function and format output as currency Use an input statement to ask the user for # of iterations using the prompt: #? [space after the ?] & assign to a variable Convert the variable to an integer Use a for loop and a range function to display all whole numbers from 1 to the user entered number Display the value of the item variable on screen in each iteration in the following...
Plot the function without using a calculator, as you will not have a calculator on the...
Plot the function without using a calculator, as you will not have a calculator on the exams. a. ? = 34 sin ?, from t = 0 to the end of the first cycle only. b. ? = 2sin3?, from t = 0 to the end of the second cycle only. c. ? = 2cos3?, from t = 0 to the end of the second cycle only. d. ? = 2sin??, from t = 0 to the end of the...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
#Python program using loop instead of numpy or pandas. Write a function to enter n student...
#Python program using loop instead of numpy or pandas. Write a function to enter n student scores from 0 to 100 to represent student score, Count how many A (100 - 90), B(89-80), C(79-70), D(69-60), F(<60) We will use numpy array OR pandas later for this problem, for now use loop Invoke the function with 10 student scores, show the result as follow: Test Enter 10 scores Enter a student score: 99 Enter a student score: 88 Enter a student...
For this assignment you will develop pseudocode and write a C++ program for a simple calculator....
For this assignment you will develop pseudocode and write a C++ program for a simple calculator. You will create both files in Codio. Put your pseudocode and C++ code in the files below. PSEUDOCODE FILE NAME: Calculator.txt C++ SOURCE CODE FILE NAME : Calculator.cpp DESCRIPTION: Write a menu-driven program to perform arithmetic operations and computations on a list of integer input values. Present the user with the following menu. The user will choose a menu option. The program will prompt...
In this program you will develop an application that will display an amortization schedule.
Using Anaconda Python, program the following:OverviewIn this program you will develop an application that will display an amortization schedule. The word "amortize" means to "To write off gradually and systematically a given amount of money within a specific number of time periods." It will show, for each month of the loan, how much of your monthly loan payment is being applied towards interest costs, and how much is actually being applied to reduce the outstanding balance (principal) of your loan.The...
Case Application 3: TEAM FUN! Tony, the new director of human resources, and Edna, the compensation...
Case Application 3: TEAM FUN! Tony, the new director of human resources, and Edna, the compensation and benefits manager, are hanging employment legislation posters in RETREAT, the TEAM FUN! employee cafeteria. Edna offers, “I remember some woman who applied for a job to advertise men’s baseball gear and sued when she didn’t get the job. The EEOC said she had no case. A couple of years ago, we moved Fred from fitness demos to stock management because he couldn’t do...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT