Re: converting letters to numbers

2013-10-20 Thread rusi
On Monday, October 14, 2013 10:32:36 AM UTC+5:30, Steven D'Aprano wrote: > On Sun, 13 Oct 2013 20:13:32 -0700, Tim Roberts wrote: > > > def add(c1, c2): > > % Decode > > c1 = ord(c1) - 65 > > c2 = ord(c2) - 65 > > % Process > > i1 = (c1 + c2) % 26 > > % Encode > >

Re: converting letters to numbers

2013-10-19 Thread Tim Roberts
Steven D'Aprano wrote: >On Sun, 13 Oct 2013 20:13:32 -0700, Tim Roberts wrote: > >> def add(c1, c2): >> % Decode >>... >Python uses # for comments, not %, as I'm sure you know. What language >were you thinking off when you wrote the above? Psssht, I know better than that. I've been readin

Re: converting letters to numbers

2013-10-16 Thread Oscar Benjamin
On Oct 16, 2013 11:54 PM, "MRAB" wrote: > > On 16/10/2013 23:39, Rotwang wrote: >> >> On 14/10/2013 06:02, Steven D'Aprano wrote: >>> >>> On Sun, 13 Oct 2013 20:13:32 -0700, Tim Roberts wrote: >>> def add(c1, c2): % Decode c1 = ord(c1) - 65 c2 = ord(c2) - 65 >

Re: converting letters to numbers

2013-10-16 Thread MRAB
On 16/10/2013 23:39, Rotwang wrote: On 14/10/2013 06:02, Steven D'Aprano wrote: On Sun, 13 Oct 2013 20:13:32 -0700, Tim Roberts wrote: def add(c1, c2): % Decode c1 = ord(c1) - 65 c2 = ord(c2) - 65 % Process i1 = (c1 + c2) % 26 % Encode return chr(i1+65

Re: converting letters to numbers

2013-10-16 Thread Rotwang
On 14/10/2013 06:02, Steven D'Aprano wrote: On Sun, 13 Oct 2013 20:13:32 -0700, Tim Roberts wrote: def add(c1, c2): % Decode c1 = ord(c1) - 65 c2 = ord(c2) - 65 % Process i1 = (c1 + c2) % 26 % Encode return chr(i1+65) Python uses # for comments, not %

Re: converting letters to numbers

2013-10-16 Thread Piet van Oostrum
Charles Hixson writes: > On 10/13/2013 10:02 PM, Steven D'Aprano wrote: >> On Sun, 13 Oct 2013 20:13:32 -0700, Tim Roberts wrote: >> >>> def add(c1, c2): >>> % Decode >>> c1 = ord(c1) - 65 >>> c2 = ord(c2) - 65 >>> % Process >>> i1 = (c1 + c2) % 26 >>> % Encode

Re: converting letters to numbers

2013-10-16 Thread Charles Hixson
On 10/13/2013 10:02 PM, Steven D'Aprano wrote: On Sun, 13 Oct 2013 20:13:32 -0700, Tim Roberts wrote: def add(c1, c2): % Decode c1 = ord(c1) - 65 c2 = ord(c2) - 65 % Process i1 = (c1 + c2) % 26 % Encode return chr(i1+65) Python uses # for comments, not

Re: converting letters to numbers

2013-10-13 Thread Steven D'Aprano
On Sun, 13 Oct 2013 20:13:32 -0700, Tim Roberts wrote: > def add(c1, c2): > % Decode > c1 = ord(c1) - 65 > c2 = ord(c2) - 65 > % Process > i1 = (c1 + c2) % 26 > % Encode > return chr(i1+65) Python uses # for comments, not %, as I'm sure you know. What language

Re: converting letters to numbers

2013-10-13 Thread Tim Roberts
kjaku...@gmail.com wrote: > >Transfer it to an uppercase letter if it's a letter, if it's not then an error. >This isn't right, I know, just testing around > >def add(c1, c2): >ans = '' >for i in c1 + c2: >ans += chrord(i)-65))%26) + 65) >return ans It's close. I think you

Re: converting letters to numbers

2013-10-08 Thread Dave Angel
On 8/10/2013 10:28, kjaku...@gmail.com wrote: > 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). > > All I have so far is

Re: converting letters to numbers

2013-10-08 Thread Mark Lawrence
On 08/10/2013 15:28, kjaku...@gmail.com wrote: 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). I'd say the requirement is

Re: converting letters to numbers

2013-10-08 Thread random832
On Tue, Oct 8, 2013, at 11:44, kjaku...@gmail.com wrote: > def add(c1, c2): > ans = '' This only makes sense if your answer is going to be multiple characters. > for i in c1 + c2: This line concatenates the strings together. > ans += chrord(i)-65))%26) + 65) The way you are

Re: converting letters to numbers

2013-10-08 Thread kjakupak
On Tuesday, October 8, 2013 11:36:51 AM UTC-4, rand...@fastmail.us wrote: > > > > Your description says capital letters, but 'a' is a lowercase letter. > > > > Does "mod 26" means A is 1, or is it 0? i.e., is A+A = B or is it A? > > > > What should your function do if the letter isn't a ca

Re: converting letters to numbers

2013-10-08 Thread random832
On Tue, Oct 8, 2013, at 10:28, kjaku...@gmail.com wrote: > 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). > > All I hav

Re: converting letters to numbers

2013-10-08 Thread Joel Goldstick
You wrote this: def add(c1, c2): ord(c1) - ord('a') + 1 ord(c2) - ord('a') + 1 First of all, this looks like homework. People will help you with concepts here, but most frown on just providing answers. With that in mind look at this: >>> ord('A') 65 >>> ord('a') 97 >>> In your assignm

Re: converting letters to numbers

2013-10-08 Thread kjakupak
On Tuesday, October 8, 2013 10:47:39 AM UTC-4, Robert Day wrote: > On 08/10/13 15:28, kjaku...@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')

Re: converting letters to numbers

2013-10-08 Thread Robert Day
On 08/10/13 15:28, kjaku...@gmail.com wrote: 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). Can you give some expected out

converting letters to numbers

2013-10-08 Thread kjakupak
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). All I have so far is: def add(c1, c2): ord(c1) - ord('a') + 1 ord(c