+ 1
I don't know why my pig latin doesn't work for the 4th test ? 🤔
Tonight I tried to do the pig latin challenge. Apparently my code is working well, but I can't see what 4th test input is, and so where is my error. Here is the code : sentence = input() sentence = sentence.split() i = 0 while i < len(sentence): letters = list(sentence[i]) letters += [letters.pop(0)] letters.append('a') letters.append('y') letters.append(' ') lettersWord = "" for x in letters: lettersWord += x sentence = [w.replace(sentence[i], lettersWord) for w in sentence] i += 1 finalSentence = "" for x in sentence: finalSentence += x print(finalSentence) Maybe it's because there is integers in the input ? Or capitals ? Any help is appreciate ! 🙏
1 Odpowiedź
+ 2
https://code.sololearn.com/cnDHonY9jXhK/?ref=app
Here's the fixed code
The problem is with this line :
sentence = [w.replace(sentence[i], lettersWord) for w in sentence]
Hack input: h g g
Here's a shorter solution to Pig Latin:
string=input()
lst=string.split()
for i in lst:
str=i[1:]+i[0]+"ay"
print("".join(str),end=" ")