Python Pushups

These are a couple exercises to kick you off with Python

Task 1: Explore Errors

  • Create a new directory in your working dir for the class:

    $ mkdir lesson01
    $ cd lesson01
    
  • Add a new file to it called break_me.py

  • In the break_me.py file write four simple Python functions:

    • Each function, when called, should cause an exception to happen
    • Each function should result in one of the four most common exceptions you’ll find.
    • for review: NameError, TypeError, SyntaxError, AttributeError

(hint – the interpreter will quit when it hits a Exception – so you can comment out all but the one you are testing at the moment)

Task 2: Puzzles

To get a bit of exercise solving some puzzles with Python, work on the Python exercises at “Coding Bat”: http://codingbat.com/python

There are 8 sets of puzzles. Do as many as you can, but try to get to at least the “Warmups”.

While the codingbat site has a great interface for submitting your solution and see if it works, we suggest you write your code in your regular text editor and get it to run on your machine first.

Put at least one solution in the lesson1 folder you created in git and submit it via pull request.