Due Friday 4/13, 5pm
Open a terminal window (mac or linux) or cygwin window (Windows). Type "python". If you have python installed, it should give you the python prompt. If you don't, it will give an error saying "command not found".
If you don't have python installed locally, you can look into installing it (post to the discussion board for assistance) or log into patas.
The default version of python on patas is 2.5, but NLTK appears to need 2.6. So if you are running on patas, invoke python with python2.6 if you want to follow along with the nltk book examples.
Note that + functions as a concatenation operator when its arguments are both strings, and as addition when its arguments are both numbers.
Now we'll try interacting with python differently: by writing a script in a text file and then sending it to python as an argument. In order to do this, you'll need a text editor that will allow you to create and edit script files. If you want to work direclty on patas, one such editor is emacs, which can invoke by typing emacs at the patas command line. Here is an emacs tutorial.
print 'hello world'
python hello.py
It should print the string 'hello world' and then give you back the command line prompt (NB: not the python prompt).
In order to create that program, the following bits of python will be useful. You can play with them through the python interpreter to get a feel for what they do.
greetings = ['Hi there!','Aloha!','Ciao!']
>>> greetings[0] 'Hi there' >>>
userinput = raw_input("Type a number: ")
usernum = int(userinput)
(Note: We're not worrying for now about making the program robust to unanticipated input, but if we were, we'd want to check that the user actually input a string of digits...)
len(greetings)- Finally, you'll need some control statements. One way to write this program uses only a while statement. Here's an example (that does something else, just to show you the functionality):
i = 0 while i < len(greetings): print greetings[i] i += 1Note that whitespace is meaningful in python, and in particular, it's the indentation of lines 3 and 4 that shows that they are part of the body of the while loop.
Alternatively, you might want to make use of an if-else statement. Here's an example:
if usernum > 3: print "That's too big." else: print "Okay."Note again the use of whitespace. Also, the else part is optional. If there is nothing for your program to do if the condition evaluates to false, then you don't need an else clause.
- After you have tried these various pieces out on the python prompt, create a script file called multilingualhw.py that has the functionality described in 4 above. Expect to go through several debugging cycles where you try running your script and then change it based on the errors that python reports.