RE: [Python] Pig Latin Translator 02-03-2014, 05:20 PM
#11
| [Python] Pig Latin Translator filter_list | |
RE: [Python] Pig Latin Translator 02-03-2014, 08:43 PM
#12
(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.")![[Image: BXqGARG.png]](https://i.imgur.com/BXqGARG.png)
RE: [Python] Pig Latin Translator 02-03-2014, 09:19 PM
#13
(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 02-03-2014, 10:41 PM
#14
(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.
![[Image: BXqGARG.png]](https://i.imgur.com/BXqGARG.png)
Users browsing this thread: 1 Guest(s)














![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)


