Question

Write a Python program that calculate and summarize the sales of every day and finds out...

Write a Python program that calculate and summarize the sales of every day and finds out who are the best employee who made more profits.

For simplicity: We assume that the program works for only two days and for only two employees. i.e. the program collects and summarize the sales of only two days for only two employees

The program accepts undefined number of sales for each employee.

For example: You could assume in the first day the first employee made 5 sales and the second employee made 3 sales. Similarly, in the second day you can assume any random number of sales for each employee.
The amount of each sales also can be chosen randomly as an integer number.

The program starts collecting data in the following order:

  1. Day 1 Employee 1 sales then
  2. Day 1 Employee 2 sales then
  3. Day 2 Employee 1 sales then finally
  4. Day 2 Employee 2 sales

User can move from (a) to (b) to (c) and finally to (d) by entering 0 (zero) value. The last entered zero will print the summary. The summary shows total sales per day and total sales per employee, and best employee for each day, that is the employee who achieves more sales in amount of money, not in number of sales.

Assume that the total sales would never be the same for both employee, i.e. one of the employee always sells more than the other. Either the first employee will sell more than the second employee, or the second employee will sell more than the first employee.

Also, assumes that the user doesn’t do any mistakes in the entry of the data.

The main function should start with the following:

sales={

        'd1':{

            'e1':{'sls':[]},

            'e2':{'sls':[]}},

        'd2':{

            'e1':{'sls':[]},

            'e2':{'sls':[]}}}

It is the declaration of ‘sales’ dictionary. As you can see, it is a multidimensional dictionary that can contain the sales of two employees in two days.

The program should use loops to produce the results of totals and winner employee.

For example:

Assume we have the following dictionary:

sales={‘d1’:2, ‘d1’:3}

Then finding the total of sales as follows is not accepted:

Sales = {'d1':2, 'd2':3}

TotalSales = sales['d1'] + sales['d2']

The accepted form of solution to find the total sales must use loops as shown below or in a similar way as long as it uses loops:

TotalSales = 0

for k, v in sales.items():

    TotalSales += v

Similar to the example above, the program should use loops to produce the results of total per employee and the total per day, and the winner employee.

You must use loops.

Below is an example of how the program runs:

Enter a sale in d1 for e1 or 0 to move to next employee or day: 1

Enter a sale in d1 for e1 or 0 to move to next employee or day: 2

Enter a sale in d1 for e1 or 0 to move to next employee or day: 3

Enter a sale in d1 for e1 or 0 to move to next employee or day: 4

Enter a sale in d1 for e1 or 0 to move to next employee or day: 5

Enter a sale in d1 for e1 or 0 to move to next employee or day: 0

Enter a sale in d1 for e2 or 0 to move to next employee or day: 6

Enter a sale in d1 for e2 or 0 to move to next employee or day: 1

Enter a sale in d1 for e2 or 0 to move to next employee or day: 2

Enter a sale in d1 for e2 or 0 to move to next employee or day: 0

Enter a sale in d2 for e1 or 0 to move to next employee or day: 4

Enter a sale in d2 for e1 or 0 to move to next employee or day: 5

Enter a sale in d2 for e1 or 0 to move to next employee or day: 0

Enter a sale in d2 for e2 or 0 to move to next employee or day: 7

Enter a sale in d2 for e2 or 0 to move to next employee or day: 8

Enter a sale in d2 for e2 or 0 to move to next employee or day: 9

Enter a sale in d2 for e2 or 0 to move to next employee or day: 0

Summary of the sales:

        Employee1   Employee2   total Winner

----------------------------------------------

Day1      15          9         24     Emp 1

Day2       9         24         33     Emp 2

----------------------------------------------

Total     24         33

Note: the above run of the program is an example. The program should be able to work with random number of sales and random amount of money for each sale. Also, it should print the correct totals and winners of highest sales per day.

The program should use the exact names suggested in the given dictionary and in the given example. And the program should produce the same text used in the example above. Notice the spaces and insert the proper ‘\n’ newlines as illustrated in the example.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# Python Code

sales={

        'd1':{

            'e1':{'sls':[]},

            'e2':{'sls':[]}},

        'd2':{

            'e1':{'sls':[]},

            'e2':{'sls':[]}}}

zero_counter = 0  # Counter to count the number of zeros

while(zero_counter!=4):

    if zero_counter == 0:

        sale = int(input('Enter a sale in d1 for e1 or 0 to move to next employee or day:'))

        if sale == 0:

            zero_counter += 1

        else:

            sales['d1']['e1']['sls'].append(sale)

    elif zero_counter == 1:

        sale = int(input('Enter a sale in d1 for e2 or 0 to move to next employee or day:'))

        if sale == 0:

            zero_counter += 1

        else:

            sales['d1']['e2']['sls'].append(sale)

    elif zero_counter == 2:

        sale = int(input('Enter a sale in d2 for e1 or 0 to move to next employee or day:'))

        if sale == 0:

            zero_counter += 1

        else:

            sales['d2']['e1']['sls'].append(sale)

    else:

        sale = int(input('Enter a sale in d2 for e2 or 0 to move to next employee or day:'))

        if sale == 0:

            zero_counter += 1

            print('Summary of the sales:')

            e1_sales = []         # To store total sales per day for e1

            e2_sales = []         # To store total sales per day for e2

            winner = []           # To store winner of the day

            total = []

            # For loop to calculate total sales per day for each employee

            for day in sales:

                e1_sales.append(sum(sales[day]['e1']['sls']))

                e2_sales.append(sum(sales[day]['e2']['sls']))

                if sum(sales[day]['e1']['sls']) > sum(sales[day]['e2']['sls']):

                    winner.append('Emp 1')

                else:

                    winner.append('Emp 2')

                total.append(sum(sales[day]['e1']['sls']) + sum(sales[day]['e2']['sls']))

            print('\tEmployee1\tEmployee2\ttotal\tWinner')

            for i in range(len(e1_sales)):

                print('Day' + str(i+1) + '\t' + str(e1_sales[i]) + '\t\t' + str(e2_sales[i]) + '\t\t' + str(total[i]) + '\t' + str(winner[i]))

        else:

            sales['d2']['e2']['sls'].append(sale)

Code Image:


Input/Output image:

Please Like If Your Problem is solved!

Add a comment
Know the answer?
Add Answer to:
Write a Python program that calculate and summarize the sales of every day and finds out...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java. Please write the output import java.util.Scanner; import java.text.Decimalformat: * This program demonstrates two-dimensional array. public...

    Java. Please write the output import java.util.Scanner; import java.text.Decimalformat: * This program demonstrates two-dimensional array. public class CorpSales public static void main(String[] args) Final int DIVS - 3; // Three divisions in the company final int QTRS = 4; // Four quarters double totalSales - e.e; / Accumulator // Create an array to hold the sales for each // division, for each quarter. double[][] sales - new double[DIVS][QTRS] // Create a Scanner object for keyboard input. Scanner keyboard = new...

  • Python 3.6 "While Loops" Write a program that adds up a series of numbers entered by...

    Python 3.6 "While Loops" Write a program that adds up a series of numbers entered by the user. The user should enter each number at the command prompt. The user will indicate that he or she is finished entering the number by entering the number 0.   Example This program will sum a series of numbers. Enter the next number (enter 0 when finished) > 5 Enter the next number (enter 0 when finished) > 2 Enter the next number (enter...

  • Write a C++ program that will calculate the total amount of money for book sales at...

    Write a C++ program that will calculate the total amount of money for book sales at an online store. For each sale, your program should ask the number of books sold and then the price for each book and the shipping method (‘S’ for standard shipping and ‘E’ for expedited shipping). The program will produce a bill showing the subtotal, the sales tax, the discount, the shipping charge, and the final total for the sale. The program will continue processing...

  • For this problem, assume salesperson data are stored in a database table named staff. Also assume the columns in the table are named name, carsSold, and totalSales Write a Python function named ge...

    For this problem, assume salesperson data are stored in a database table named staff. Also assume the columns in the table are named name, carsSold, and totalSales Write a Python function named getSalesSortedByNames. Your function will have 2 parameters. The first parameter is a database cursor and the second parameter is a float. Your function should start by retrieving those rows in the staff table whose totalsales field is equal to the second parameter. (The next paragraph shows the Python...

  • USING PYTHON: Write a program that reads an unspecified number of integers and finds the ones...

    USING PYTHON: Write a program that reads an unspecified number of integers and finds the ones that have the most occurrences. For example, if you enter 2 3 40 3 5 4 –3 3 3 2 0, the number 3 occurs most often. Enter all numbers in one line. If not one but several numbers have the most occurrences, all of them should be reported. For example, since 9 and 3 appear twice in the list 9 30 3 9...

  • Show Me The Money. (15 points) Write a C++ program that calculates how much a person...

    Show Me The Money. (15 points) Write a C++ program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the second day, four pennies the third day, and so on, with the daily pay doubling each day the employee works. The program should ask the user for the number of days the employee worked during the month and should display a table showing how much the salary was...

  • Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops...

    Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations,...

  • C program (File Processing - Writing) The same Bicycle shop that contracted you to write the...

    C program (File Processing - Writing) The same Bicycle shop that contracted you to write the double array problem in HW5 has now decided that they want to keep a log of all employee transactions. Write a program that will allow users to enter in their name (you only need to use first name) and the item that they sold (for example, “James Bicycle”). After each employee types in a sale, your program should record that sale in a file...

  • Please include function in this program Write a C program that will calculate the gross pay...

    Please include function in this program Write a C program that will calculate the gross pay of a set of employees utilizing pointers instead of array references. You program should continue to use all the features from past homeworks (functions, structures, constants, strings). The program should prompt the user to enter the number of hours each employee worked. When prompted, key in the hours shown below. The program determines the overtime hours (anything over 40 hours), the gross pay and...

  • This is JAVA. Must write a short description of this program, usually a sentence or two...

    This is JAVA. Must write a short description of this program, usually a sentence or two will be sufficient. All the classes, methods and data fields should be clearly documented (commented). Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 4 percent and the county sales tax is 2 percent. The program should display the amount of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT