Now You Code 3: List of numbers

This example will demonstrate how to parse an input string into a list of numbers. You will then demonstrate it's a list of numbers by calculating the count, sum(), min(), max() and average of the numbers using Python's len(), sum(), min(), and max() functions.

Example Run #1:

    Enter numbers separated by a space: 10 5 0

    Numbers: [10.0, 5.0, 0.0]
    Count: 3
    Min: 0.0
    Max: 10.0
    Sum: 15.0
    Average: 5.0

As usual, devise your plan, write the program, THEN figure out how to handle bad input in Example run #2.

HINT: Use split() to make a list from the input, use a loop to convert each item in the list to a float

Start out your program by writing your TODO list of steps you'll need to solve the problem!

Step 1: Problem Analysis

Inputs: a string of numbers separated by a space eg. 10 5 1

Outputs: the count, sum, min, max and average of the numbers

Algorithm (Steps in Program):

TODO: Write algorithm here

In [1]:
# Step 2: Write solution
numbers = [] # start with an empty list

Step 3: Questions

  1. Re-write the solution so that it handles bad input (place in a new cell):

Example Run #2: (Handles bad input)

    Enter numbers separated by a space: 5 mike 3

    Error: mike is not a number!
  1. Explain which part of the solution could be refactored into a function?

Answer:

  1. What would be be the input(s) and output of that function?

Answer:

Step 4: Reflection

Reflect upon your experience completing this assignment. This should be a personal narrative, in your own voice, and cite specifics relevant to the activity as to help the grader understand how you arrived at the code you submitted. Things to consider touching upon: Elaborate on the process itself. Did your original problem analysis work as designed? How many iterations did you go through before you arrived at the solution? Where did you struggle along the way and how did you overcome it? What did you learn from completing the assignment? What do you need to work on to get better? What was most valuable and least valuable about this exercise? Do you have any suggestions for improvements?

To make a good reflection, you should journal your thoughts, questions and comments while you complete the exercise.

Keep your response to between 100 and 250 words.

--== Write Your Reflection Below Here ==--