Apr-27-2017, 01:52 AM
Hi.
Sorry for the poor English, I'm not a native speaker.
The boring code I'm writing works as follows. The user inputs a number T. The user is then prompted, T times, to provide a couple of values A and N, such that the N integers that come after A and their sum will be printed as the output. I've worked everything out just fine, but I'm supposed to get the sequence of integers in a line and their sum on another line, otherwise the automatic corrector my retarded professor uses won't accept it. To print the sequence in the same line, I used the argument end = ' '. However, this argument makes everything that comes after it appear on a single line, and the sum is supposed to appear in a new line. What I mean is, if you type 1 3, you're supposed to get
1 2 3
6
But my program gives
1 2 3 6
So, how do I make the sum of the numbers appear on a new line? Here's my code. The three final lines are what's really important.
Sorry for the poor English, I'm not a native speaker.
The boring code I'm writing works as follows. The user inputs a number T. The user is then prompted, T times, to provide a couple of values A and N, such that the N integers that come after A and their sum will be printed as the output. I've worked everything out just fine, but I'm supposed to get the sequence of integers in a line and their sum on another line, otherwise the automatic corrector my retarded professor uses won't accept it. To print the sequence in the same line, I used the argument end = ' '. However, this argument makes everything that comes after it appear on a single line, and the sum is supposed to appear in a new line. What I mean is, if you type 1 3, you're supposed to get
1 2 3
6
But my program gives
1 2 3 6
So, how do I make the sum of the numbers appear on a new line? Here's my code. The three final lines are what's really important.
T = int(input('Number of pairs: ')) lizt = [] for i1 in range(1, T): A, N = input('Insert a couple of numbers').split() A, N = int(A),int(N) for i2 in range(A, A+N): lizt.append(i2) print(i2, end =' ') sm = sum(lizt) print(sm)