Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: UNSURE 0.222 X-Spam-Level: ** X-Spam-Evidence: '*H*': 0.56; '*S*': 0.00; "'c',": 0.16; "'o',": 0.16; 'ord': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'result.': 0.19; 'header :User-Agent:1': 0.23; '(or': 0.24; 'define': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'fixed': 0.29; 'converting': 0.30; 'mod': 0.31; 'subject:numbers': 0.31; '(i.e.': 0.33; 'equal': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'done': 0.36; 'should': 0.36; 'example,': 0.37; 'expected': 0.38; 'message-id:@gmail.com': 0.38; 'mapping': 0.38; 'to:addr :python-list': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'letters': 0.60; 'numbers': 0.61; 'back': 0.62; "you've": 0.63; 'email addr:gmail.com': 0.63; 'sum': 0.64; 'between': 0.67; '26,': 0.68; 'capital': 0.73; 'presumably': 0.84; 'tricky': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=O2RvU/ANxBWfPQEIPmSi/iRPuoY5NiUu3tCUjiglHOY=; b=GgLahBjZOtjp5i2FQK4H6Bq2To13MqXT0Ylf1KE9cPLUWIicdsfsl+JnPnG9202ozn Jcy64E0YXEH/f7qP597zDhJl1tdzEZ/Suknco9wxf3FTOQiZ5gChWwYOsit+9gU3Lfst 3jZd1vx5KkraPyuTJytY++KswV/7cSxkLDX7NWfJysVy9YFr2b7s7oayy1qZGaoIpTug 2iH0LXUExe5sPAJSYUbDHQ3amG43lboon0WpCI6zjXZcqPpH8lhYgjZzxypLqVOOSkIk 8Xjyslvc/vFt4j4wA37aamKdJqc5MR7qxiWRe40Q5eY4P1oB0fi5aD9wI2tZZcl/CPRM jfHg== X-Received: by 10.152.120.5 with SMTP id ky5mr1719038lab.18.1381243661482; Tue, 08 Oct 2013 07:47:41 -0700 (PDT) Date: Tue, 08 Oct 2013 15:47:39 +0100 From: Robert Day User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: converting letters to numbers References: <26151b64-4f5e-4ee9-81ac-26679932f43d@googlegroups.com> In-Reply-To: <26151b64-4f5e-4ee9-81ac-26679932f43d@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Tue, 08 Oct 2013 16:48:19 +0200 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 12 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381243701 news.xs4all.nl 15937 [2001:888:2000:d::a6]:37067 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56407 On 08/10/13 15:28, kjakupak@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 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.