Last answered:

31 Mar 2022

Posted on:

30 Mar 2022

0

Question 9: Why do some rows need print() to go to the next line while the other don't?

Why do some rows need "print()" to go to the next line while the others don't?

1 answers ( 0 marked as helpful)
Instructor
Posted on:

31 Mar 2022

0

Hey Sachintha,

Thank you for reaching out!

Consider the following example:
image.png
In the first print, we have told Python to print out the letter 'a' and then leave an empty space. The next print, which will be 'b', will therefore end up next to 'a'. However, if we don't tell Python explicitly to put 'b' next to 'a', it will put it on a new line. That's exactly what happens with the letter 'c'. By default, the print function prints on a new line, unless told otherwise.

Here is a commented version of the code provided by Giles.
image.png
Hope this helps!

Kind regards,
365 Hristina

Submit an answer