converting letters to numbers

kjakupak at gmail.com kjakupak at gmail.com
Tue Oct 8 10:51:24 EDT 2013


On Tuesday, October 8, 2013 10:47:39 AM UTC-4, Robert Day wrote:
> On 08/10/13 15:28, kjakupak at gmail.com wrote:
> 
> Can you give some expected outputs? For example, add('A', 'B') should 
> 
> presumably return 'C', and add('M', 'B') should presumably return 'O', 
> 
> but what about add('A', 'A') or add('Z', 'Z')?
> 
> 
> 
> It feels like the only tricky bit is mapping letters to numbers (i.e. 
> 
> does A equal 1 or 0?), which you'd do by subtracting a fixed value from 
> 
> the result of chr. Once you've done that, you'd do the arithmetic to get 
> 
> a number between 1 and 26 (or 0 and 25), then add the same fixed value 
> 
> to that and call ord on the result.

Expected output is add('C', 'E') returns 'G'; where 'C' and 'E' correspond to 2 and 4 respectively with sum 6, corresponding to 'G'.



More information about the Python-list mailing list