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
7 ответов
+ 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!
+ 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.
+ 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?
+ 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=' ')
+ 1
Dude thanks man I appreciate it
+ 1
Invalid syntax line 8. Man this is melting my brain
+ 1
Thanks again. I was over comicating it. Its working great now