CS 140
Practice problems on Lists

Here are some practice programming problems using lists and tuples.

These are not to be handed in, though you should feel free to ask questions about any of them outside of class. Remember that programming is an activity that you learn by doing.

  1. Write a program that reads a list of numbers from the user; the list terminates when the user enters 0. After all of the
    input the program should print the list.
  2. Change program (1) so the list is printed in reverse order.
  3. Change program (1) to use a tuple instead of a list.
  4. Change program (1) to print the average value of the list as well as each of the values in the list.
  5. Write an inventory program for a store. This should let the user enter objects and the number of each in the inventory.
    At the end the program prints the entire inventory, alphabetized by the names of the objects. For example, the input might be

       Object, or blank line to exit: widget
       Number of widgets: 24

       Object, or blank line to exit:
    thingamabob
       Number of thingamabobs: 3

       Object, or blank line to exit:
    gizmo
       Number of gizmos: 15

       Object, or blank line to exit:
    <return>

    The output will then be:

       gizmos:          15
       thingamabob: 3
       widget:           24

5. Change program (4) so that the output is in order from smallest number to largest number. For the example given it will be

         thingamabob: 3
         gizmos:          15
          widget:           24

6. Write a program that inputs a list of values (doesn't matter if they are numbers or strings) and then prints all of the values
     that appear in the list more than once.

7. Write a program that inputs a list of numbers and outputs basic statistical information about the list: minimum and maximum
    values, average value, standard deviation (the square root of variance; we gave a formula for this in class -- ask me if you
    can't find it), and median (middle value). Each of these is pretty easy to calculate; just write a function to find each of them.