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

Joel Goldstick joel.goldstick at gmail.com
Fri Aug 10 21:53:32 CEST 2012


On Fri, Aug 10, 2012 at 3:33 PM, Selby Rowley Cannon
<selbyrowleycannon at ymail.com> wrote:
> On 10/08/12 20:07, Joel Goldstick wrote:
>>
>> On Fri, Aug 10, 2012 at 2:57 PM, Selby Rowley Cannon
>> <selbyrowleycannon at ymail.com> wrote:
>>>
>>> On 10/08/12 18:17, Joel Goldstick wrote:
>>>>
>>>> On Fri, Aug 10, 2012 at 1:05 PM, Selby Rowley Cannon
>>>> <selbyrowleycannon at ymail.com> wrote:
>>>>>
>>>>> I have written a small application to encrypt some text. The script
>>>>> looks
>>>>> fine to me, but it won't run and I can't figure out why. I have
>>>>> attached
>>>>> it,
>>>>> if anyone knows why it doesn't work please let me know!
>>>>>
>>>> What do you mean 'it won't run'?  Do you get an error with Traceback?
>>>>
>>>> I glanced at your code, and your dictionary ends like this: , 'X':'A',
>>>> 'Y':'B', 'Z':'C',
>>>>
>>>> There is no closing brace
>>>
>>> OK,
>>>
>>>    File "./crypto.py", line 6
>>>      def encrypt():
>>>        ^
>>> SyntaxError: invalid syntax
>>>
>> First, don't reply to me, reply to the group.  That might mean
>> choosing reply all.
>>
>> So, your first problem is that the dictionary isn't closed.  This is
>> causing the error at line 6
>>
>> fix that and find your next error.  It looks like there are lots of them
>>
>> With such a small file you would do better to just post the code
>> directly.  That way if people see problems they can point them out in
>> the body of the reply
>>
>> good luck
>
> #!/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

>     if EorD == 'Encrypt' or EorD == 'encrypt':
>         encrypt()
>     elif EorD == 'Decrypt' or EorD == 'decrypt':
>         decrypt()
>     else:
>         print('Encrypt or Decrypt?')
>
> 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
>



-- 
Joel Goldstick


More information about the Tutor mailing list