Linguistic Gaming with Python

Python Practice 1

As with all programming languages (and languages in general), practice makes perfect. These exercises are meant for you to practice your programming skills.

This first exercise is just meant to get you a little bit familiar with Python and with programming in general.

Note: all Python programs should be saved with the Suffix .py. This lets the computer and the Python interpreter know that the lines of code you have written are meant to be in Python.

Python Installation and First Steps

IDLE vs. editors

Dawson works with an IDLE (Integrated Development Environment). This is not quite what we did in class. You can either work with IDLE as Dawson describes, or work with an editor and call up Python from the shell/terminal. The following exercises assume you are working with an editor and call Python up from the shell/terminal while working with MacOSX.

Calling up Python in the Shell

Python 2 vs. Python 3

There has been a period of change-over between Python Versions. Most of the material found on-line (and the new books) assume Python 3. In this course, we will use Python 3, but we will be confronted by Python 2 every now and then. In fact, there are only a few major differences between the two and they are not hard to remember.
Differences between Python 2 and Python 3
Python 2 Python 3
print "Hello World" print ("Hello World")
raw_input("\nPlease enter something:\n") input("\nPlease enter something:\n")

Creating and Saving a Python Program: this is best done by using editors that work well for text/utf-8. Examples are emacs, Aquaemacs, vi, TextEdit, Notepad, Kommodo, Textwrangler). Another option are so-called IDE (integrated development environment). Students in the past have found that they prefer Kommodo.

Now write the following lines of code into an editor of your choice and save the program in a file called

A First Program

#simple first program for Python 3
print("Hello World!")             #Output 

The Program

Exercise 1.1. Copy or type the program into an editor, save it and try it out.
Exercise 1.2. Add more print commands and try out the new version of the program.

You can run programs you have written and saved in a number of ways.

Dawson Exercises
Do the "Challenges" at the end of Dawson's Chapter 1.

Pretty Printing
Now let's move on to some pretty printing. The aim is to get a nicely formatted list with names and office information. Like this:

Name                 Place
-----------          -------
Miriam Butt	     G220
MacRoom              G209
Common Room          G119

Exercise 1.3. Type in or copy the program below into an editor, save it and try it out.
Exercise 1.4. What do the comma, the "\n" and the "\t" do? (\n generally stands for "newline")
Exercise 1.5. Now write a program that produces the above list of names with places, all nicely formatted.


print("Miriam   "),

Please hand in the last part of the exercise (Pretty Printing) to miriam.kuemmel at uni konstanz by Tuesday the 31st of October by 11 am.