iterables, like lists, and for loops are building blocks of glorious software
python 2 home > fundamentals review mini-projects

Python fudamentals review


Our original data analytics planning and curricular revision planned that students who have comleted python 1, or are python 2 ready, are basically flient with the Deitel text content through about the beginning of chapter 9 (files). To the extent that this fluency has gaps, these exercises encourage you to write code to accomplish mini-tasks using study resources.

Use the buttons above to navigate to the page sections

list Files & loops


listLesson sequence

  1. Build a shared understanding of our file I/O tools on the white board using our linked resources

Exercise 1: Looping to a file

Study the following file contents. Generate a program in Python to reproduce this structure. NOTE: You'll need to use two for() loops, nested. You can try seeing if you can print the pattern out first to the console, then replace the calls to print() with calles to yourfile.write().

file example

Exercise 2: String formatting program specification

  1. Download the following text file of names: file link
  2. Your desired program output is a formal greeting for individuals whose names exist in a text file in the order: first last. The output should look like this:
  3. output
  4. The process of generating these greetings should take place in two functions: one should read in a file given a file name (assumed to be in the working directory) and extract the name in a single line. The second method should receive a line of text (i.e. a name in the form first last) and generate the greeting. Remember, you'll need to invert the string since we're using string formatting, not string concatenation.