Step 3 – Full ASCII messages
We can use ord() and chr() to convert whole messages rather than just deal with single characters one at a time.
This is a bit more complex, but it will work.
Convert text to ASCII
This is quite easy to do.
- Start a new Python program
- Use an input statement to get the user to enter a word or phrase
- Then create a blank variable called cipherText. We need a blank variable so that we can add to it
- Use a For loop to look at each letter of the user's word or phrase in turn
- Use the same code as you did in Step 1 to convert theLetter to it's ASCII code
- Now add this to what you already have in the variable cipherText. This builds up the converted code one letter at a time
- Outside the loop, print the cipherText
Save your program and run it.
Start with a short message like "hello" and then try and make the message a bit more complex. Does it deal with symbols like & and spaces? What about a long message?