Lesson goal: Data Science: Initial values for max and min

Previous: Find the minimum value | Home | Next: Visualize data with a plot

From the last two lessons on finding the minimum and maximum value of some numbers, you might have a lingering thought: were your choices for the inital values of the variables max and min the best? Would you code work in all cases? Was your code 'robust?'

As an example, suppose you set your min initially to 100, but suppose your data file contained a bunch of numbers that were all only in the 1000s? Your code would say 100 was in the minimum, but 100 isn't even in the data file!

Alternatively, suppose you set your initial max to 0, but your data file contained all negative numbers?

See where software bugs can come from?

The best way to handle this is to set min and max to some number that is actually in your data file. How will you do this?

How about setting min or max equal to the first number in your data file? It may or may not end up being the eventual minimum or maximum value, but at least it's in the data file, as a reference for starting out the comparisions.

Now you try. Try to complete the code and find the minimum number in the file sample.dat.

Type your code here:


See your results here:

The code won't run as is! What will you put in for the min = ?? line? Think: not a number like before, but the first number in your data file. Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.