Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68668

Re: Python - Caeser Cipher Not Giving Right Output

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'that?': 0.05; 'subject:Python': 0.06; 'lines,': 0.07; 'variables': 0.07; 'bug.': 0.09; 'happen?': 0.09; 'modulo': 0.09; 'operator,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'wrote': 0.14; 'be:': 0.16; 'dave.': 0.16; 'letters.': 0.16; 'lower-case': 0.16; 'overwriting': 0.16; 'parentheses': 0.16; 'precedence': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Not': 0.16; 'traceback.': 0.16; 'tried:': 0.16; 'variable.': 0.16; 'thursday,': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'split': 0.19; 'input': 0.22; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'wondering': 0.29; "doesn't": 0.30; 'yes.': 0.31; 'another': 0.32; 'display': 0.35; 'case,': 0.35; 'no,': 0.35; 'test': 0.35; 'but': 0.35; 'add': 0.35; 'picking': 0.36; 'done': 0.36; 'thanks': 0.36; 'error.': 0.37; 'two': 0.37; 'to:addr :python-list': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'dave': 0.60; 'letters': 0.60; 'march': 0.61; 'numbers': 0.61; 'matter': 0.61; "you're": 0.61; 'email addr:gmail.com': 0.63; 'term': 0.63; 'more': 0.64; 'different': 0.65; 'between': 0.67; '20,': 0.68; '26,': 0.68; 'experiment': 0.84; 'multiplying': 0.84; 'angel': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: Python - Caeser Cipher Not Giving Right Output
Date Fri, 21 Mar 2014 00:02:39 -0400 (EDT)
Organization news.gmane.org
References <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> <mailman.8341.1395371543.18130.python-list@python.org> <bda05813-d186-41ea-a40d-5d36f90a8fed@googlegroups.com>
X-Gmane-NNTP-Posting-Host dpc6744198232.direcpc.com
X-Newsreader PiaoHong Usenet NewsReaders 1.36
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8343.1395374292.18130.python-list@python.org> (permalink)
Lines 67
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1395374292 news.xs4all.nl 2876 [2001:888:2000:d::a6]:48115
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:68668

Show key headers only | View raw


 dtran.ru@gmail.com Wrote in message:
> On Thursday, March 20, 2014 11:16:50 PM UTC-4, Dave Angel wrote:
>> dtran.ru@gmail.com Wrote in message:
>> > 
>> 
>> > def two(c1 , c2):
>> 
>> >     c1 = chartonum(c1)
>> 
>> >     c2 = chartonum(c2)
>> 
>> >     return numtochar(c1 + c2 %26)
>> 
>> 
>> 
>> You're missing some parentheses in that line. To test your
>> 
>>  understanding,  try picking some numbers for c1 and c2. Display
>> 
>>  c1 + c2 % 26, and see if the result is always between 0 and
>> 
>>  25.
>> 
>> 
>> 
>> Or look up the term precedence in your textbook.
>> 
>
>> DaveA
> 
> Thanks for your input Dave. Would the line be:
> 
> return numtochar(c1 + c2 %26) 

That would be the line I tagged,  yes.

> 
> c1 and c2 are lower-case letters. 

No, they're not , you just got done overwriting the letters with
 numbers.   That's a bad habit, reusing local variables with data
 of different meanings,  but I was trying to focus on the line
 with the bug.


> And I was wondering how I would add the partenthesis because I tried:
> 
> return numtochar(c1 + c2 (%26)) and it gave me an error. 

Please help us to help you by actually showing the traceback. 
 Doesn't matter in this case, but...

What order do you want the add and the modulo to happen?  Use the
 parentheses to say so.  Or split it into two or more lines, with
 another variable. 

Perhaps you don't understand that % is an operator,  just like +
 and *.  If you were told to add a and b before multiplying by c,
 how would you write that? Try it, just as you tried the other
 experiment I recommended. 




-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python - Caeser Cipher Not Giving Right Output dtran.ru@gmail.com - 2014-03-20 19:50 -0700
  Re:Python - Caeser Cipher Not Giving Right Output Dave Angel <davea@davea.name> - 2014-03-20 23:16 -0400
    Re: Python - Caeser Cipher Not Giving Right Output dtran.ru@gmail.com - 2014-03-20 20:23 -0700
      Re: Python - Caeser Cipher Not Giving Right Output Dave Angel <davea@davea.name> - 2014-03-21 00:02 -0400
      Re: Python - Caeser Cipher Not Giving Right Output Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-21 03:58 +0000
        Re: Python - Caeser Cipher Not Giving Right Output dtran.ru@gmail.com - 2014-03-20 21:23 -0700
          Re: Python - Caeser Cipher Not Giving Right Output Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-21 09:50 +0000
      Re: Python - Caeser Cipher Not Giving Right Output Rustom Mody <rustompmody@gmail.com> - 2014-03-20 21:02 -0700
      Re: Python - Caeser Cipher Not Giving Right Output Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-22 08:22 -0600
        Re: Python - Caeser Cipher Not Giving Right Output Rustom Mody <rustompmody@gmail.com> - 2014-03-22 10:29 -0700

csiph-web