Outputs in different line using single print statement... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Outputs in different line using single print statement...

I have 2 variables, I want to print sum, difference and product of those variables in 3 different line using only one print statement.....Print(x+y, x-y, x*y) is giving results in same line

27th Oct 2018, 4:33 PM
Uthpala
9 Answers
28th Oct 2018, 3:26 AM
David Ashton
David Ashton - avatar
+ 2
print(x+y, x-y, x*y, sep='\n')
27th Oct 2018, 4:44 PM
HonFu
HonFu - avatar
+ 1
yes it worked....tq so much.....I'm beginner trying with simple programs
27th Oct 2018, 4:50 PM
Uthpala
+ 1
print has predefined that each word is separated by a white space and that in the end there's a newline. If you want something else, you can write sep='anystringyouwant' and end='anystringyouwant'. Example: print('apples', 'pears', 'bananas', sep=' or ', end='!') -> apples or pears or bananas!
27th Oct 2018, 4:55 PM
HonFu
HonFu - avatar
0
@HonFu syntax error :(
27th Oct 2018, 4:47 PM
Uthpala
0
Try again - I've corrected a typo!
27th Oct 2018, 4:49 PM
HonFu
HonFu - avatar
0
Great....got it.....please recommend me videos or free online courses or books for beginners
27th Oct 2018, 4:58 PM
Uthpala
0
I don't know English videos or books (I am from Germany). Maybe someone else can help out?
27th Oct 2018, 5:55 PM
HonFu
HonFu - avatar
0
Thanks @David
2nd Nov 2018, 2:52 PM
Uthpala