Me and one of my friends are seeing how far we can condense a Pig Latin translator from the ground up. Here is my code:
output = []
outputWord = ""
def translate(inp):
global output
words = inp.split()
for i in range(len(words)):
outputWord = ""
curWord = words[i]
if curWord[0] == "a" or curWord[0] == "o" or curWord[0] == "e" or curWord[0] == "u" or curWord[0] == "i":
outputWord = curWord + "way"
elif curWord[1] == "a" or curWord[1] == "o" or curWord[1] == "e" or curWord[1] == "u" or curWord[1] == "i":
for count in range(len(curWord)-1):
outputWord = outputWord + curWord[count+1]
outputWord = outputWord + curWord[0] + "ay"
else:
for count in range(len(curWord)-2):
outputWord = outputWord + curWord[count+2]
outputWord = outputWord + curWord[0] + curWord[1] + "ay"
output.append(outputWord)
translate(raw_input(""))
print(' '.join(output))
We aren’t accounting for capitals or punctuation. So far, I’ve gotten to 21 lines, and he’s still bugfixing his code.
I’ve seen a thing where people have condensed if/elif/else statements to one line, but I’m not sure if it’ll work with this.
Has anyone got any other ideas for condensing?
NOTE: Please don’t condense my code for me. We are doing everything ourselves, but we can ask for help. If you can see a way I can condense my code, direct me to somewhere that explains how, or explain it to me without my exact case in mind, just something similar.
Or if I have a mistake/improvment, you can try to explain it in the same way.
aqwek_ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.