0

why does this work like this ?

27th Dec 2022, 6:03 PM
Albert
7 Answers
+ 8
Each line of output is the result of s after a single iteration of the loop. The reason that the output is not all on one line is because the print statement is being called multiple times, and each time it is called, it prints a new line. If you want the output to be on a single line, you could modify the code as follows: https://code.sololearn.com/c4xhykL8JzhL/?ref=app
27th Dec 2022, 6:31 PM
Sadaam Linux
Sadaam Linux - avatar
+ 3
Hello, Well for this, you need to do it in multiple lines. Firstly, the array word is declared with some data items (4 items). Then it assigns an empty string to 's' Next it iterates through each item in the array 'word' Within the for loop, it assigns what is at 'w' and a space to s It then outputs the contents of 's' I do not think this can be done all in one line, at least not from my knowledge, hope that helps
27th Dec 2022, 6:24 PM
Hassanah
Hassanah - avatar
+ 1
Hi, this is the Q&A section. Here you can ask programming related questions. What is your question?
27th Dec 2022, 6:07 PM
Lamron
Lamron - avatar
+ 1
thanks šŸ™
27th Dec 2022, 6:31 PM
Albert
+ 1
šŸ™
27th Dec 2022, 6:32 PM
Albert
0
can you pls explain why it doesn't goes in one line?
27th Dec 2022, 6:13 PM
Albert
0
word=["ER","AS","IQ","NULL"] s = "" for w in word: s += w + " " print(s)
27th Dec 2022, 6:13 PM
Albert