0

here in my code extra blank space is printing after each row last elements and extra line break after last element .

https://code.sololearn.com/cVvd04NcAbU1/?ref=app please help in debugging this code to remove extra blank space after each row last elements and extra new line after last row

19th Feb 2019, 11:18 AM
कामेश
कामेश - avatar
1 Odpowiedź
+ 2
Why is the trailing space in every line a problem? You still want it gone? And after you printed out the last row of your matrix, you want the cursor to remain at the end of that line? You can do it like this: for i in range(1,r+1): for j in range(1,c+1): a=a+1 print(a,end=' ' if j!=c else '') print(end='\n' if i!=r else '') I changed the loop variables to i and j so that I can still access c and r for a ternary expression.
19th Feb 2019, 11:46 AM
HonFu
HonFu - avatar