CS209 lab2


http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l2.html




  1. You should first experiment with some of the simple programs at http://www.maths.nuigalway.ie/~gettrick/teach/cs209/progs/.
  2. Write a program in PYTHON that calculates the median of a set of distinct input integers (input at the command line). The median is some number x such that half the numbers are above x and half below. For example,
    • median of 1,3,5,7 is 4
    • median of 1,2,2,7 is 2
    • median of 1,2,3,7 is 2.5
    (note - as in the last example - the median may not necessarily be an integer). Your program must read from the command line. The simplest way of doing this is probably as follows: On your computer, look for software called "NX Client" and start it up. This will automagically connect you to the main linux machine on campus, leas.nuigalway.ie. Log on to that computer using your usual ID and password. Once logged on, you can start up a terminal. Create your PYTHON file, lets say lab2.py, just using a text editor, e.g. vi, EMACS, gedit etc. Then you can run your file by typing at the command line "python lab2.py".
  3. Adapt your program to check that in the input list, no two numbers are repeated, and if they are print a helpful message to the user.
  4. (GIGO! (garbage in,....)) Adapt your program so that if the user runs the program without any command line arguments, a helpful message is returned on how to use the program.

© NUI, Galway