CT240 lab3
http://geminga.it.nuigalway.ie/~gettrick/courses/CT240/labs/l3.html
-
For this lab you must submit a printout of 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). Any questions asked should be answered on a plain sheet of paper.
-
The above material should be given to Paul or left in the cardboard box marked CT240 in the mail room (room IT415) on the 4th floor of the IT Building
before
the deadline of 5pm
Monday 6th. October 2008. You will lose 20% for each day
(or part of day) the lab is late. If you have a genuine reason for
submitting a late lab, please contact Paul before the lab
due date/time.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated. Please see
http://www.nuigalway.ie/engineering/documents/plagiarism_guide_students
_v4.pdf. You risk getting zero for your lab if it is found to be
plagiarized.
A palindrome is a word (or sequence of letters) that reads the
same when read backwards: examples are dad, deed, navan, kayak
etc.
By contrast, we define a word to be a near-palindrome if
it reads the same backwards except for (exactly) one pair of
letters - or put another way, if we only have to change one
single letter to make it a palindrome. Examples are cavan (change the
c to an n, or change the n to a c, to get a palindrome),
abcdcea (change the b to an e, or change the e to a b...),
door, trot,...
(Note that all 3- and 2- letter words are either palindromes or
near-palindromes.)
-
Write a program that uses a WHILE
loop to calculate if a
given input word (string) is a palindrome. You should use the
built-in python function raw_input to read in the string
from the user, and the output of your program should be
TRUE or FALSE.
You must use a while loop. Do not use the reverse list
method.
-
Write a program that uses a FOR
loop to calculate if a given
input word/string is a near-palindrome. (Remember:
"palindrome" and "near-palindrome" are mutually exclusive: a
word cannot be both).
You must use a for loop.
©
NUI, Galway