Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Here is a program. Write down exactly what it shows, on paper.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Go line by line. For each print(), decide what goes between the pieces and what comes after.
print("a", "b", "c") has the normal space between pieces: a b c.sep="" has nothing between the pieces: abc.sep=" + " puts + between the pieces: a + b + c.print("a", end="") shows a and does not start a new line.print("b") shows b on the same line, because the line before did not end the line. So we get ab.Answer: The output is four lines:
a b c
abc
a + b + c
abCommon mistake. Forgetting that the fifth line joins the fourth. end="" removes the new line after a.
Log in to join the discussion.
Loading…