Hey, my code works, but didn't pass on test 4, and i don't unsderstand why. Pls someone help me about it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Hey, my code works, but didn't pass on test 4, and i don't unsderstand why. Pls someone help me about it

Pig latin

18th Nov 2021, 7:11 PM
Caio Picinin
Caio Picinin - avatar
6 Answers
+ 3
Why are you using a condition? sentence = input() pig_latin ='' words = sentence.split() for word in words: pig_latin = pig_latin + word[1:] + word[0] + 'ay ' print(pig_latin)
18th Nov 2021, 10:13 PM
Solo
Solo - avatar
+ 2
At first I did not pay attention to your condition, because of unnecessary, presumably that the problem is in it, but looking now I can say that the code must pass all tests. The condition compares each word with the last in the sentence. I would make it easier: print(pig_latin[:-1]) ☺️
19th Nov 2021, 2:04 AM
Solo
Solo - avatar
+ 1
sentence = input() pig_latin ='' words = sentence.split() for word in words: if word not in words[-1]: pig_latin = pig_latin + word[1:] + word[0] + 'ay' + ' ' else: pig_latin = pig_latin + word[1:] + word[0] + 'ay' print(pig_latin)
18th Nov 2021, 7:12 PM
Caio Picinin
Caio Picinin - avatar
+ 1
I'm using the condition to have a space between different words, and with the last word there is no need
18th Nov 2021, 11:45 PM
Caio Picinin
Caio Picinin - avatar
+ 1
Don't worry about it, testing is not responsive to this. Or do you want to do this for yourself?
19th Nov 2021, 1:38 AM
Solo
Solo - avatar
+ 1
In fact i wanna do that for myself, to have a code that works better. But thank you
19th Nov 2021, 1:54 AM
Caio Picinin
Caio Picinin - avatar