Unlike most labs, this lab is due before you leave today.
After the lab, you should be
We'll practice writing several Python programs, each in their own text file. Name the files lab4.1.py through lab4.4.py.
Your programs will be graded on correctness, efficiency, style, and how well you tested them. Make sure you adhere to the good development and testing practices we discussed in class. Your code should be readable and your output should be useful and well-formatted.
After you've developed a correct solution to each program, restart IDLE or close and reopen the IDLE "shell" by running the program again (using F5), demonstrate that the program works using several good test cases, and save the output to a file named lab3.x.out, where x is the problem number.
In your algorithm, remove spaces from the string. You should consider upper and lower case letters as the same, .i.e., "A man A plan A canal Panama" is a palindrome. (What string method can you use to accomplish that before processing?) However, you don't need to consider punctuation as special cases.
You may want to have a variable that keeps track of if the string is a palindrome. (What type of variable would be most suited for that task, given that a string is either a palindrome or it isn't?)
For this problem, you should strive for efficiency, but, given our current knowledge of programming building blocks, your solution may be slightly inefficient, i.e., even though you already "know" that a string is not a palindrome, you will keep checking that if it is. You can write an efficient solution for an extra 3 points. (Talk to me about your solution if you're curious about the extra points.)
This program encodes and decodes Ceasar ciphers. Enter some text: i like the lions at the zoo Enter an integer key (between -25 and + 25): 1 The result is: j mjlf uif mjpot bu uif app |
Notice that the alphabet wraps around. The 'z' in 'zoo' became an 'a' in the encoded message. You should be able to use the same program to decode this message as follows:
This program encodes and decodes Ceasar ciphers. Enter some text: j mjlf uif mjpot bu uif app Enter an integer key (between -25 and + 25): -1 The result is: i like the lions at the zoo |
Note that spaces will have to be handled specially.
Rhetorical question: why is the limit on keys between -25 and +25?
Your script should also call the function you defined so that you can test your function.
turnin
directory.
(Review the UNIX handout if you don't
remember how to do that.)
printLab.sh
command.
Again, you should probably print from the labs
directory.
Print the file using the lpr
command introduced in the
first lab.
Unlike most labs, this lab is due before you leave today.