Sinisterly
[Python] Pig Latin Translator - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: [Python] Pig Latin Translator (/Thread-Python-Pig-Latin-Translator)

Pages: 1 2


RE: [Python] Pig Latin Translator - Eclipse - 02-03-2014

(02-03-2014, 04:13 PM)BreShiE Wrote: Nice work Sparks, but if you're going to post code, you should comment out your code to help others who want to learn.

Thanks for the tip! I remember feeling dumb when I couldn't understand others code. I will definitely add comments next time.


RE: [Python] Pig Latin Translator - Equinox - 02-03-2014

(02-03-2014, 05:20 PM)Sparks Wrote: Thanks for the tip! I remember feeling dumb when I couldn't understand others code. I will definitely add comments next time.

I have another comment. Writing out all of those "or first ==", etc. can get annoying here's an easy way to check the vowels instead of all of those or's:

Code:
vowels = ['a','e','i','o','u'] if len(original) > 0 and original.isakpha(): if first in vowels: print(new_word)

Basically we defined "vowels" to be a list with the brackets( [] ). Everything we list between the two is under "vowels". So we check if first is in vowels and if it is, it will print new_word.
If not well you get the idea.

This is my modified version including everything noted above:

Code:
original = input("Word: ") pyg = 'ay' word = original.lower() first = original[0] new_word = original + pyg listed = ['a','e','i','o','u'] if len(original) > 0 and original.isalpha(): if first in listed: print(new_word) else: new_word = original[1:] + original[0] + pyg print(new_word) else: print("One word at a time, no numbers or punctuation.")



RE: [Python] Pig Latin Translator - Eclipse - 02-03-2014

(02-03-2014, 08:43 PM)Duubz Wrote: I have another comment. Writing out all of those "or first ==", etc. can get annoying here's an easy way to check the vowels instead of all of those or's:

Code:
vowels = ['a','e','i','o','u'] if len(original) > 0 and original.isakpha(): if first in vowels: print(new_word)

Basically we defined "vowels" to be a list with the brackets( [] ). Everything we list between the two is under "vowels". So we check if first is in vowels and if it is, it will print new_word.
If not well you get the idea.

This is my modified version including everything noted above:

Code:
original = input("Word: ") pyg = 'ay' word = original.lower() first = original[0] new_word = original + pyg listed = ['a','e','i','o','u'] if len(original) > 0 and original.isalpha(): if first in listed: print(new_word) else: new_word = original[1:] + original[0] + pyg print(new_word) else: print("One word at a time, no numbers or punctuation.")

Thanks! You're very good at this..


RE: [Python] Pig Latin Translator - Equinox - 02-03-2014

(02-03-2014, 09:19 PM)Sparks Wrote: Thanks! You're very good at this..

I've been practicing for quite a while now. Once you get the hang of it you'll be pretty good too. But im no professional.