0

Why is this outputting twice

And if I remove for word in newstr from the print command..it displays this: E l l h a y O r l d w a y I cant get it to just print once and as a sentece https://code.sololearn.com/cgO728c6Nr3W/?ref=app

10th Sep 2020, 5:45 AM
Jason Kennedy
7 odpowiedzi
+ 2
Line 8 should be changed to: print(word[1:] + word[0] + 'ay', end='') Because you’re already iterating over the words in the for loop. Note the end='' which tells Python not to put a newline at the end of the print sentence; without it, the words would be on seperate lines. Also, line 5 should be changed to: if word[0] in 'aeiou': If you put square brackets around the aeiou string, then Python will think you’re asking if it’s in the list, and since word[0] has to be a single character, it cannot be in list with the only element 'aeiou'. You’ll also have to put end='' at the end of line 6. Hope this helps!
10th Sep 2020, 9:14 AM
Rowsej
Rowsej - avatar
+ 5
It’s because you’re doing it for each word in the for loop. So, if you enter three words, it will print the output 3 times.
10th Sep 2020, 6:02 AM
Rowsej
Rowsej - avatar
+ 2
Not sure how to make it print only the sentence once doing what to each word in the loop? I'm just trying to pig latin it what else is it doing to the word?
10th Sep 2020, 6:22 AM
Jason Kennedy
+ 2
# You can get rid of the for stuff in line 8. This is the debugged code: string= "hello there" newstr = string.split() for word in newstr: if word[0] in "aeiou": print(word + "yay", end=' ') else: print(word[1:] + word[0] + 'ay', end=' ')
11th Sep 2020, 6:23 AM
Rowsej
Rowsej - avatar
+ 1
Dude thanks man I appreciate it
11th Sep 2020, 2:00 AM
Jason Kennedy
+ 1
Invalid syntax line 8. Man this is melting my brain
11th Sep 2020, 2:26 AM
Jason Kennedy
+ 1
Thanks again. I was over comicating it. Its working great now
11th Sep 2020, 6:36 AM
Jason Kennedy