Lab Dates: Wednesday-Thursday, 27 September & 3 October 2012
Today's lab focuses on simple string manipulation from Chapter 5.
For the first challenge, you do not need to define a function, only use the python shell to evaluate the mathematical expression. Take the number and use it as the URL to go to the next challenge. Make sure to add '.html' to your answer.
For the second challenge, let us first look at the Python program
# text2numbers.py # A program to convert a textual message into a sequence of # numbers, utlilizing the underlying Unicode encoding. def main(): print("This program converts a textual message into a sequence") print ("of numbers representing the Unicode encoding of the message.\n") # Get the message to encode message = input("Please enter the message to encode: ") print("\nHere are the Unicode codes:") # Loop through the message and print out the Unicode values for ch in message: print(ord(ch), end=" ") print() main()
Try the program with the string given in the second challenge. You will see all the numberic codes corresponding to the characters of the encoded message
Now we will decode the message by using the Python program
# decodeMessage.py # A program to decode the Python Challenge (2) message. # Each character must be mapped to the character 2 places ahead. def main(): print("This program decodes a textual message") print("Each character is replaced with the character 2 places ahead in the alphabet.") print("The characters \"\'\", \".\", \"(\", \")\", and \" \" are not decoded.\n") # Get the message to encode message = input("Please enter the message to decode: ") print("\nHere is the decoded message:") # decode the message 1 character at a time decodedMessage = "" for ch in message: if (ch == '.') or (ch == "'" ) or (ch == '(') or (ch == ')') or (ch == ' '): decodedMessage = decodedMessage + ch else: codeNumber = ord('a') + ((ord(ch) - ord('a') + 2) % 26) decodedMessage = decodedMessage + chr(codeNumber) print("\nThe decoded message is:", decodedMessage) print() main()
After completing your program, go to Assignments in Blackboard and click on the link: Lab 5. Use the file upload interface to upload your program. Remember to click the Submit button before closing the lab exercise.
With the remaining time, start Problem Set 4.