This assignment has three parts.
Part One: Programming
Write a program to encode and decode a message. Use the following guidelines to write your
program:
1. Think of a secret message you want to encode. Be creative! Maybe a famous quote, a favorite
lyric, or your personal motto.
2. Using the ord() and chr() functions, encode and decode the message.
3. Optional: Ask the user to guess the message before revealing it.
Display the encoded message in binary, or include a twist by adding 2 to the number.
When decoding, remember to reverse the steps.
4. Neatly print the encoded and decoded messages to the screen.
5. Write the pseudocode for this program. Be sure to include any needed input, calculations, and
output.
Insert your pseudocode here:
# 1. Set a secret_message variable with the desired message
secret_message = "I love python!"
# 2. Define a function encode_message(message) to encode the message using only chr() and
ord()
- Initialize an empty string encoded_message
- For each character in the message:
- Convert the character to its ASCII value using ord()
- Append the ASCII value followed by a space to encoded_message
- Return the stripped encoded_message
# 3. Define a function decode_message(encoded_message) to reverse the encoding process
- Split the encoded_message into a list of ASCII values using space as a delimiter
- For each ASCII value in the list:
- Convert the ASCII value to its corresponding character using chr()
- Join the characters to form the decoded_message
- Return the decoded_message
# 4. Optionally, ask the user to guess the message before revealing it
- Get user input for a guess
# 5. Display encoded and decoded messages
- Encode the secret_message using encode_message function
- Decode the encoded_message using decode_message function
- Print the encoded message
- If the user's guess matches the secret_message:
- Print a congratulations message
- Otherwise:
- Print an incorrect guess message and reveal the secret_message
- Print the decoded message
Part Two: Code the program
Use the following guidelines to code your program:
4. To code the program, use the Python IDLE.
5. Using comments, type a heading that includes your name, today’s date, and a short description
of the program.
6. Follow the Python style conventions regarding indentation and the use of white space to
improve readability.
7. Use meaningful variable names.
Example of expected output: The output for your program should resemble the following
screen shot. Your specific results will vary depending on the choices you make and the input
provided.
Insert a copy of your code from IDLE here:
# 1. Secret message
secret_message = "I love python!"
# 2. Encode and Decode functions
def encode_message(message):
encoded_message = ''.join(str(ord(char)) + ' ' for char in message)
return encoded_message.strip()
def decode_message(encoded_message):
decoded_chars = [chr(int(char)) for char in encoded_message.split()]
decoded_message = ''.join(decoded_chars)
return decoded_message
# 3. Optional: Guess the message
user_guess = input("Guess the secret message: ")
# 4. Display encoded and decoded messages
encoded_message = encode_message(secret_message)
decoded_message = decode_message(encoded_message)
print("\nEncoded Message:")
print(encoded_message)
if user_guess.lower() == secret_message.lower():
print("Congratulations! Your guess is correct.")
else:
print("Incorrect guess. The secret message is:", secret_message)
print("\nDecoded Message:")
print(decoded_message)
Part Three: Post Mortem Review
Complete the Post Mortem Review (PMR). Write thoughtful two- to three-
sentence responses to all the questions in the PMR chart.
Review Question Response
What was the purpose of your program? To create a game in which the player must guess
the secret password by viewing the ASCII code of
the password.
How could your program be useful in the real It can help teach people about ASCII code and how
world? it works, as well as entertain people with a fun
game.
What is a problem you ran into, and how did you I kept mixing up the ord and char functions, so I
fix it? would have to re-order my code. Once I got a hang
of it, I wasnt making the same mistake again.
Describe one thing you would do differently the I would add more than one password and add hints
next time you write a program. to make the game easier.