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' Now a little bit of arithmetic should get you to/from 1. How you handle upper/lower case issues is up to you, but if they aren't important then the string upper() and lower() methods may help too. I don't know what you do with punctuation, you didn't say but you should be able to get the core done using the above. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor