[Tutor] Script won't run for no apparent reason

Dave Angel d at davea.name
Fri Aug 10 22:07:50 CEST 2012


On 08/10/2012 03:53 PM, Joel Goldstick wrote:
> On Fri, Aug 10, 2012 at 3:33 PM, Selby Rowley Cannon
> <selbyrowleycannon at ymail.com> wrote:
>>> <SNIP>
>> #!/usr/bin/env python3
>>
>> import random
>> values = {'a':'d', 'b':'e', 'c':'f', 'd':'g', 'e':'h', 'f':'i', 'g':'j',
>> 'h':'k', 'i':'l', 'j':'m', 'k':'n', 'l':'o', 'm':'p', 'n':'q', 'o':'r',
>> 'p':'s', 'q':'t', 'r':'u', 's':'v', 't':'w', 'u':'x', 'v':'y', 'w':'z',
>> 'x':'a', 'y':'b', 'z':'c', 'A':'D', 'B':'E', 'C':'F', 'D':'G', 'E':'H',
>> 'F':'I', 'G':'J', 'H':'K', 'I':'L', 'J':'M', 'K':'N', 'L':'O', 'M':'P',
>> 'N':'Q', 'O':'R', 'P':'S', 'Q':'T', 'R':'U', 'S':'V', 'T':'W', 'U':'X',
>> 'V':'Y', 'W':'Z', 'X':'A', 'Y':'B', 'Z':'C'}
>> def encrypt():
>>     textInputE = input('Please enter the text you wish to encrypt: ')
>>     textInputE.list()
>>     for Eletter in textInputE.list():
>>         try:
>>             print (values[Eletter])
>>         except KeyError:
>>             print ('Sorry, that input couldn\'t be parsed as text. Try
>> again.')
>>             input('Press Enter')
>> def decrypt():
>>     textInputD = input('Please enter the numbertext you wish to decrypt')
>>     textInputD.list()
>>     for Dletter in textInputD.list():
>>         try:
>>             print (values[Dletter])
>>         except KeyError:
>>             print ('Sorry, that input couldn\'t be parsed as numbertext from
>> our cipher. Please try again.')
>>             input('Press Enter')
>>
>> while True:
>>     EorD = input('Encrypt or Decrypt: ')
> so are you sure the line above is really what you have in your code?
> check the quotes
The clue was actually in his code.  See his shebang line -- he's using
Python 3.  So the error is on the data that the user inputs.
The other clue, that I noticed, was that his innermost error was on line
1, "called" from input().
Anyway, the cure is to use raw_input() everywhere instead.

>> <SNIP>
>>
>> Thanks, I am not quite used to this client yet. The next error is:
>>
>> Traceback (most recent call last):
>>   File "crypto.py", line 25, in <module>
>>     EorD = input('Encrypt or Decrypt: ')
>>   File "<string>", line 1, in <module>
>> NameError: name 'Encrypt' is not defined
>>
>
>


-- 

DaveA



More information about the Tutor mailing list