0

\n command failure

Heres the program: prin("1. Can we print lists without any entities in it?") first = [] print(first) print("As you see we can. The command was:\n first = []\nprint(first)\n2. Can we print 2 lists in one line?") first = [1,2,3] second = [7,8,9] print(first,second) print("We can do it too. Now how it was done:") print("first = [1,2,3]") print("second = [7,8,9]") print("print(first,second)") print("3. Can > or < use two numbers, or more?") if 20 > 15 and 5: print("20 is bigger than 15 and 5") p

1st Jan 2018, 4:15 PM
Rokas Morkūnas
Rokas Morkūnas - avatar
6 Réponses
+ 4
I don't know much python but I added a backslash like this \n\ : print("As you see we can. The command was:\n\ first = []\nprint(first)\n2. Can we print 2 lists in one line?") and it works. But btw, I don't think you can use > or < to compare with two numbers at once, for example (20 > 15 and 30) gives the same result as (20 > 15 and 5) because it is equivalent with (20 > 15 and True).
1st Jan 2018, 4:40 PM
lion
lion - avatar
+ 3
in other words, what Paul means is that you pressed Enter after \n I thought that was intentional, for esthetic reasons, and I added a backslash like in C++ to make it work :)
2nd Jan 2018, 9:44 AM
lion
lion - avatar
+ 2
and the \n crashes
1st Jan 2018, 4:15 PM
Rokas Morkūnas
Rokas Morkūnas - avatar
+ 2
I have tried your code: print("1. Can we print lists without any entities in it?") first = [] print(first) print("As you see we can. The command was:\nfirst = [] \nprint(first)\n2. Can we print 2 lists in one line?") first = [1,2,3] second = [7,8,9] print(first,second) print("We can do it too. Now how it was done:") print("first = [1,2,3]") print("second = [7,8,9]") print("print(first,second)") print("3. Can > or < use two numbers, or more?") if 20 > 15 and 5: print("20 is bigger than 15 and 5") If you copy it like this it works. Somehow you pushed the new line key after the first \n.
1st Jan 2018, 4:49 PM
Paul
Paul - avatar
+ 2
@paul Jacobs what is new line key
1st Jan 2018, 8:04 PM
Rokas Morkūnas
Rokas Morkūnas - avatar
+ 2
It is also known as "enter" and on my keyboard it's sign is an arrow to the left.
1st Jan 2018, 8:09 PM
Paul
Paul - avatar