CS209 lab2
http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l2.html
-
For this lab you should submit all source code (PYTHON
files), and the result(s) of running the program on (a few)
test cases.
The source code must
be well presented (indenting, spaces, reasonable variable/function names,
etc.) and must include comments (as a rough guideline - aim to have nearly as
many comments as lines of code).
-
The above material should be uploaded to BLACKBOARD
before
the deadline of 5pm
Monday 9th. February 2015. You will lose 20% for each day
(or part of day) the lab is late. (In BLACKBOARD, you should attach your
PYTHON program under "Attach File" in the section "2. Assignment Materials".
If you are including anything other than PYTHON code, e.g. answers to
questions, etc, it can be cut/pasted in to "Submission" under "2.
Assignment Materials".)
If any of this is unclear, you should ask the Teaching Assistant in the lab.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated.
You risk getting zero for your lab if it is found to be
plagiarized.
-
You should first experiment with some of the simple programs at
http://www.maths.nuigalway.ie/~gettrick/teach/cs209/progs/.
-
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. One way of doing this
is as follows: On your computer, from the Start menu, get a command prompt.
Find where the python executable is (on my machine it is, for example, at
C:\Python34\python.exe). Then go to the folder/directory where your python file
is located (you can use cd to move around from folder to folder, cd ..
moves up a folder). When you are in the same directory as your file (say the file is
called test.py) you can type in
C:\Python34\python.exe test.py arg1 arg2 (for example) to run your program with
the 2 command line arguments arg1 and arg2. If any of this is unclear, be sure to put your hand
up and ask the teaching assistant in the labs.
-
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.
-
(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