# Total mass of N balls N = 100 # no. of balls M = 0 # partial sum, which becomes total mass for i in range(N): # repeat N times m = i # m_i (mass of i-th ball) M += m # i.e. M=M+m ( add m_i to partial sum ) print(M)