Hey guy, anyone know why can’t I use the backlash in this case, and how I can make another line without using PRINT function. Thank you so much for your help!
what the backslash does is allowing you put the code on multiply lines:
print "hello", \ "world"
if you want the output by print on multiply lines, use the new line character (
\n) which needs to be part of the string
if the exercise asks for 2 print statements, you need to add them, then new line character won’t get you through
Thank you so much for your help, but it seems so hard for me to know how to do. I did try, but it doesn’t work. Dont know how
the new line character needs to be part of string:
the code should be on a single line, the new line character will make the output display over two lines
Now, I got it. But I still get trouble when I put the variables following. Do you know how I can fix it.
-Thank you so much-
that depends on how you put the variables.
as i told you, for the exercise (to pass) you most likely need two print statements
what do you want? Put the code on multiply lines using the continuation character (
\), which will give a single line output or use the new line character (
\n) which put all code on a single line, and the output on multiply lines
given you currently use the continuation character, the code just continues, so you shouldn’t use print on line 5, correct:
print "hello",\ "world"
print "hello",\ print "world"
the last one is wrong, because if you would remove the continuation character you would get:
print "hello", print "world"
which is obviously wrong. See how the continuation character works? It allows you to put the code on multiply lines, but you should read it as a single line of code
I understand it, but I still get troubles when I put the variables following.
I am so sorry. This is so new to me.
because you put another print statement in when printing
b, if we would read it as a single line of code:
print "hello", a, print "hello", b
its obviously wrong.
it should be:
print "hello", a, "hello", b
the same logic applies when using continuation character:
print "hello", a, \ "hello", b
duh? i told you, the continuation character is for the programmer to put code on multiple lines which gives a single line output, if you want the output over multiply lines, you need to use the new line character (
\n), telling you want the code following it printed on a new line
But where I should put \n, right after the argument or after the variables
i told you,
\n should be part of a string. Where you put it is up to you. You can do:
print "hello", a, "\n"
you can put it where you want the line to start
Ok. Finally, I got it. Thank you so so much. One more question, Do u know how I can use the END function
end is introduced in python3, codecademy uses python2.
Oh. Ok. But thank you so much for your patience. I dont know how i can learn without your help!.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.