Skip to content

ExerciseSession1 Basics

Katy Huff edited this page Feb 21, 2012 · 2 revisions

Exercise Session 1 : The Basics

In this exercise session you will :

  1. Create your own github repository
  2. Fork the repository of a friend
  3. Navigate the shell
  4. Manipulate strings, files, and integers
  5. Write your own bona fide python program

Create Your Own Github Repository

It's so easy. Name it ExcerciseSession .

Just login and follow [[the instructions. | http://help.github.com/create-a-repo/]]

Add a File the Repository

Start with a .py file that will contain your solution program.

You may want to start by defining a main() function.

Build a Python Program

The text files you reorganized in the shell session should be in a single directory and should all have the extension .txt.

  1. Create a function that finds all of the filenames and puts them in a list. ( hint: import os, glob ).
  2. Create a function that, given a line from a file, returns true if that line contains a question with an N response and false otherwise.
  3. Create a function that, given the filename and the line that has a missing response, fixes the missing entry by appending that line with a default answer of gender M.
  4. Use these functions together (probably within the main function) to create a loop that, for each file in the file list, reads each line, determines whether it is missing a response, and if it is, fixes the missing entry in place within the files.

Be sure to commit your changes often and occasionally push your commits to your repository, especially when your solution is complete.

I'll share my solution at the end of the session.

Fork the Repository of a Friend

Fork their repository, check their solution, and improve something.

Push your improvement to your fork of their repository.