Doing it in a list comprehension is a waste of time, it seems, mainly since you have to have a separate print statement for the final sum (due to the no-newline limit).
97 bytes:
E=print
f=lambda x:[E(g:=i**x+x)or g for i in range(x)]
E(end='SUM: '+str(sum(f(int(input())))))
Instead, there's a couple changes I noted.
E=print
A=int(input())
B=[]
for D in range(A):C=D**A+A;B.append(C);E(C)
E(end='SUM: '+str(sum(B)))
First, you can do B+=[C]
instead of B.append(C)
. That loses 5 bytes for 93. But we can also just use B as an integer and add - that saves us from having to do a sum later, so we can shave off a total of 11 for a total of 85.
E=print
A=int(input())
B=0
for D in range(A):C=D**A+A;B+=C;E(C)
E(end='SUM: '+str(B))
We can then do an inline variable assignment when printing D**A+A
to save bytes as well, from C=D**A+A;B+=C;E(C)
to E(G:=D**A+A);B+=G
. This saves one byte, for 84 bytes.
E=print
A=int(input())
B=0
for D in range(A):E(G:=D**A+A);B+=G
E(end='SUM: '+str(B))
Lastly, calling str
is long and unwieldy. There's no backticks to call repr
like in Python 2, but we can just use autocasting print arguments to do it anyway. From E(end='SUM: '+str(B))
to just E('SUM: ',B,end='')
. We add two single quotes and a comma, but lose out on 5 bytes from the str()
, for a total of -2 and a final byte count of 83.
E=print
B=0
A=int(input())
for D in range(A):E(G:=D**A+A);B+=G
E('SUM: ',B,end='')
input
that doesn't exist? If so, you can useinput
to print without a newline for the ending sum. \$\endgroup\$