Practice working with a list of numbers

Assignment Help Basic Computer Science
Reference no: EM131427482

Objective:

  • Practice working with a list of numbers.
  • Practice writingfunction definitionsthat useparametersandreturna value.
  • Practice using astring accumulator.

Instructions:

Your employer needs a program that analyzes the monthly sales figures for each division. 

Write a Python program that allows the user to enter a series of numbers and places the numbers (not string values) in a list.  Each number entered by the user is the monthly sales amount for one division.  Use a sentinel-controlled loop to get input from the user and place each value entered into the list as long as the value is not negative.  As soon as any negative value is entered, stop the loop (without putting that illegal value into the list).

One objective of this assignment is to apply algorithms we have studied to solve problems. You will do this by writing a function definitionto implement each algorithm.  Every function must get information only from its parameters, not from "global" variables.  Several of these tasks can also be accomplished with built-in functions.  In those cases, your code should demonstrate both approaches and show that the results are the same.

Add code to your program to do the following:

  1. Write a function definition that uses a loopand astring accumulatorto produce andreturn astringresultthat includes the user-entered sales figures formatted to look similar to this when it is printed:
    {$12.95, $1,234.56, $100.00, $20.50}
    Notice the dollar signs, commas, digits after the decimal point, and curly braces.  Plan this one on paper before you start writing code.  Add code that calls this function and prints the result.
  2. Show thehighestnumber in the list -- the sales leader! Do this in two ways. First, use the built-in 'max' function. Then, write your own 'max2' function definition that accomplishes the same thing by using a loop to find the highest value.
  3. Show thelowestnumber in the list -- the sales loser. Do this in two ways. First, use the built-in 'min' function. Then, write your own 'min2' function definition that accomplishes the same thing by using a loop to find the lowest value.
  4. Show the total sales for the company for the month -- thesumof all the numbers in the list. Once again, write a function definition that uses a loop and an accumulator to compute this sum.
  5. Show theaverageof all the numbers in the list. (Be sure to carefully check the result!)
  6. Ask the user to enter athreshold(a number). Write a function that takes a list and the threshold as parameters, and returns a new list that contains all values in the original list that aregreaterthan or equal to the threshold-- these divisions get awards for high sales! The new list may, of course, be empty.

Program Organization:

The program should be organized as a series of function definitions. The 'main' function should contain the user interface as well as code that "calls" the other functions and then shows the results to the user. Only the 'main' function should interact with the user. No other function should print anything; rather, each function "returns" a value.  Do not use any global variables.

Testing:

As always, be sure to test each result using representative data to make sure it is correct, and include comments showing documented test cases in your program.

Reference no: EM131427482

Edge set adjacent to ay

Which of the following is the edge set adjacent to AY? Which of the following is the degree of Y? Which of the following is the sum of the degrees of the vertices? Which of th

What is the goal of information systems planning?

What is the goal of information systems planning? What are the steps of the traditional systems development life cycle? What is prototyping? What is an RFP? What is typically

Internet and use of communication impacted the outcome

Quick and easy! Please answer the below questions in 400 or more words. Needs to be orginial content please. 1. How has the Internet and use of communication impacted the outc

Receive funding for select planning projects

Imagine that you are trying to receive funding for select planning projects. Compare and contrast the attributes of business continuity and disaster recovery plans, and su

Should an economic model describe reality exactly

Draw and explain a production possibilities frontier for an economy that produces milk and cookies. What happens to this frontier if disease kills half of the economy's cow

Various translation reside

1. Describe how one string value like "Hello" can be displayed in different languages. How is the string stored in the widget? Where does the various translation reside?

Find the magnitude and the direction of the resultant force

Physics Two forces, one of 30 N and the other of 50 N, act on an object. If the angle between the forces is 40°, find the magnitude and the direction of the resultant force.

The economy is self-regulating

The classical school of economic thought believes that the economy is self-regulating and should be left alone to adjust naturally.  Keynesian's, on the other hand, believe th

Reviews

Write a Review

 
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd