[Tutor] encoder decoder problem
David Rock
david at graniteweb.com
Tue Nov 27 17:33:28 EST 2018
> On Nov 27, 2018, at 16:17, Alan Gauld via Tutor <tutor at python.org> wrote:
>
> On 27/11/2018 21:04, Kamina Kamtarin wrote:
>> A De/Coder. Think back to 3rd grade when you passed notes to friends in
>> class. We can't let the teacher see what we're writing so we used a code.
>> A=1, B=2, C=3, etc. Your job is to create a program which does the
>> following:
>>
>> 1. Presents the user with a menu choice: encode or decode
>> 2. Depending on what they chose you will either encode letters into
>> numbers (seperated by dashes) or decode a series of numbers (separated by
>> dashes) into letters.
>> 3. For example:
>> - "How are you?" would encode as "8-15-23 1-18-5 25-15-21?"
>> - "8-15-23 1-18-5 25-15-21" would decode as "How are you?"
>
> Look at the builtin ord() and chr() functions.
>
> For example ord('A') -> 65 and ord('a') -> 97
>
> Similarly chr(97) -> 'a' and chr(65) -> ‘A'
I would also try to break up your requirements into smaller pieces. For example, some things to solve:
How would you get input?
How would you break up a string into individual characters?
How would you break up an encoded string into individual numbers?
How would you put the characters/numbers back together for output?
Have you started writing any code? What have you tried so far?
—
David Rock
david at graniteweb.com
More information about the Tutor
mailing list