[Tutor] Dictionaries
Hello, I am having a problem with a small application I am writing. I have to have the user input the key, then have the program output the value associated with it. A way to inform the user that the key they entered is not in the dictionary or somefing would be nice also. Fank you for your help, -Selby ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Dictionary
Version: 2.7 OS: Ubuntu 12.04 LTS I am writing a small translation app for Rydish (A language that exists in the same way Klingon does, invented by my company for a[n] RPG). Here is my current method of translation: Edictionary = {'English keys':'Rydish values'} TextEng = raw_input('Please enter your text: ') if TextEng in Edictionary: print(TextEng + ' traslates to ' + Edictionary[TextEng]) But I have found that this is only going to translate one word at a time. I thought about a loop of somesort, but I can't seem to find one that won't still force the user to translate one word at a time. Can anyone tell me how to translate a full sentance/several sentances? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
Mailing list; I have a small, [for the most part] functioning translation app for Rydish, a language created for the sole purpose of an RPG. The only problem is when I enter a word that has not yet been translated, I get this error: Traceback (most recent call last): File "translator.py", line 25, in Etranslate() File "translator.py", line 14, in Etranslate print(Edictionary[Eword]) KeyError: 'world' Is there a way to print a user-freindly message instead of displaying a traceback? Thanks, -Selby ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] check against multiple variables
I am using a hash table in a small randomization program. I know that some hash functions can be prone to collisions, so I need a way to detect collisions. The 'hash value' will be stored as a variable. I do not want to check it against each singular hash value, as there will be many; I need a way to check it against all hash values at once (if possible.) Sorry for those who like to reference, but there is no source code as of yet. I will need this to be solved before I can start writing, sorry! If you need any extra info let me know. -Selby ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Script won't run for no apparent reason
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! #!/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: ') if EorD == 'Encrypt' or EorD == 'encrypt': encrypt() elif EorD == 'Decrypt' or EorD == 'decrypt': decrypt() else: print('Encrypt or Decrypt?') ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Script won't run for no apparent reason
On 10/08/12 20:07, Joel Goldstick wrote: On Fri, Aug 10, 2012 at 2:57 PM, Selby Rowley Cannon wrote: On 10/08/12 18:17, Joel Goldstick wrote: On Fri, Aug 10, 2012 at 1:05 PM, Selby Rowley Cannon 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: ') 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 EorD = input('Encrypt or Decrypt: ') File "", line 1, in NameError: name 'Encrypt' is not defined ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Script won't run for no apparent reason
On 10/08/12 20:53, Joel Goldstick wrote: On Fri, Aug 10, 2012 at 3:33 PM, Selby Rowley Cannon wrote: On 10/08/12 20:07, Joel Goldstick wrote: On Fri, Aug 10, 2012 at 2:57 PM, Selby Rowley Cannon wrote: On 10/08/12 18:17, Joel Goldstick wrote: On Fri, Aug 10, 2012 at 1:05 PM, Selby Rowley Cannon 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 EorD = input('Encrypt or Decrypt: ') File "", line 1, in NameError: name 'Encrypt' is not defined OK, I have put it back into Python 2.7, and now I get: Traceback (most recent call last): File "crypto.py", line 27, in encrypt() File "crypto.py", line 7, in encrypt textInputE.list() AttributeError: 'str' object has no attribute 'list' ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
OK, I have some code, and it uses glob.glob('*.py') to find all the python files in the current directory. Just thought i'd ask, would: glob.glob('C:\*.py') (Windows), or glob.glob('/*.py') (*nix) find all the python files on the system? Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Website form data input
Hello, I am aiming to write a program that inputs a list of codes into an HTML text field, one by one, entering the next code if it is incorrect, but stopping when the code is correct. I've got down putting the codes into a list, and 'for' looping though it (maybe 'while' the entered code is incorrect?) but I don't know how to enter text into a text field in a website. All help greatly appreciated, -Selby___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] LCM
Hey, I've been trying to write a function to find the Lowest Common Multiple of two numbers, but it isn't working and I've kinda hit a dead end on the thought-process end of things. Anyone mind looking at it, and tell me what's wrong? (I hop you don't think it's too long to put in an email) Code: def lowestCommonMultiple(a, b, amount): #k float(amount) if a == b: print 'You cannot find the LCM of the same number twice.' else: numbersList = list(range(amount)) aMultiples = [] bMultiples = [] for aNumber in numbersList: aMultiples.append(a*aNumber) for bNumber in numbersList: bMultiples.append(b*bNumber) if aMultiples[1] == bMultiples[1]: print 'The LCM of ', a, ' and ', b, ' is ', aMultiple[1] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] LCM
On 14/11/12 18:27, Dave Angel wrote: On 11/14/2012 12:52 PM, Selby Rowley Cannon wrote: Hey, I've been trying to write a function to find the Lowest Common Multiple of two numbers, but it isn't working and I've kinda hit a dead end on the thought-process end of things. Anyone mind looking at it, and tell me what's wrong? (I hop you don't think it's too long to put in an email) Code: def lowestCommonMultiple(a, b, amount): #k float(amount) if a == b: print 'You cannot find the LCM of the same number twice.' else: numbersList = list(range(amount)) aMultiples = [] bMultiples = [] for aNumber in numbersList: aMultiples.append(a*aNumber) for bNumber in numbersList: bMultiples.append(b*bNumber) if aMultiples[1] == bMultiples[1]: print 'The LCM of ', a, ' and ', b, ' is ', aMultiple[1] Which are you interested in, finding what's wrong with the code, or a simpler way to actually find an LCM ? Is this an assignment, or just part of a bigger program you're writing? a.) Finding what's wrong with the code; b.) Part of a bigger program. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor