Skip to content

HFP CH 4

Jacob Amey edited this page Aug 19, 2013 · 1 revision

Chapter 4 - Sort it out

(data in files and arrays)

32 Pages Long

Description:

This chapter covered three main concepts. Reading data from a file, Arrays, and sorting the data from an array or file. This Chapter introduced you to using outside data. You managed and organized this data for simplicity and ease of use through the data structures learned through out the chapter.

The Code:

The code revolved around a Surfing Competition. Your tasked with coming up with a program that will take the recorded scores from the event and display the results to a scoreboard. You needed to display 1st, 2nd, and 3rd place. For this your code needed to read the data results from the competition. Split out the scores and sort from highest to lowest. You then assigned the top three scores to an array.

Main Concepts Covered:

  1. files - reading data stored on disk.
  2. arrays - a collection variable that holds multiple data items that can be accessed by index.
  3. Sorting - arranging a collection in a specific order.

Python Tools Covered:

  • open() - open a file for processing.
  • close() - close a file.
  • for - iterate over something.
  • string.split() - cut a string into multiple parts.
  • [] - the array index operator.
  • array.append() - add an item to the end of an array.
  • array.sort() - sort an array, lowest-to-highest.
  • array.reverse() - change the order of an array by reversing it.
Clone this wiki locally