[Tutor] Converting letters to numbers?

Kristen Jakupak kjakupak at gmail.com
Tue Oct 8 19:42:49 CEST 2013


I have to define a function add(c1, c2), where c1 and c2 are capital
letters; the return value should be the sum (obtained by converting the
letters to numbers, adding mod 26, then converting back to a capital
letter).

What I have so far is
def add(c1, c2):
    ans = ''
    for i in c1 + c2:
        ans += chr((((ord(i)-65))%26) + 65)
    return ans

Any guidance would be great, thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131008/676246a5/attachment.html>


More information about the Tutor mailing list