+ 1

What wrong with code?

n=int(input('n:')) #1*n+2*(n-1) k=1 while k>n: sum(k*n) k+=1 n-=1 print(sum)

23rd Sep 2019, 1:45 PM
Andriy Popovich
Andriy Popovich - avatar
4 odpowiedzi
+ 1
Ohh... just replace the line sum=k*n with sum=sum+k*n It will sum over all terms.
23rd Sep 2019, 3:28 PM
Vijay Meena
+ 1
n=int(input('n:')) #1*n+2*(n-1) k=1 sum=0 while k<n: sum=k*n k+=1 n-=1 print(sum) I think this is the right code.
23rd Sep 2019, 1:57 PM
Vijay Meena
+ 1
I'm needed to calculate sum of these 1*n+2*(n-1).... While n not be a > first factor
23rd Sep 2019, 2:18 PM
Andriy Popovich
Andriy Popovich - avatar
0
There is no function called "sum".
23rd Sep 2019, 1:53 PM
KfirWe
KfirWe - avatar