Answer to Question #229157 in Python for kaavya

Question #229157

Sum of K powers

Write a program to print the sum of the Kth power of the first N natural numbers.

Input

The first line of input is an integer N. The second line of input is an integer K.

Explanation

In the given example, the sum of first

5 natural numbers power of 3.The sum should be 13 + 23 + 33 + 43 + 53

Therefore, the output should be

225.

Sample Input 1

5

3

Sample Output 1

225

Sample Input 2

2

8

Sample Output 2

257




1
Expert's answer
2021-08-26T18:39:08-0400
N=int(input("Enter an interger N: "))
K=int(input("Enter an interger K: "))
output=0
for number in range(1,N+1):
    output+=pow(number,K)
print(output)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS