CT240 lab3


http://geminga.it.nuigalway.ie/~gettrick/courses/CT240/labs/l3.html




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.)

  1. 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.
  2. 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