SUM OF POWERS:
you are given a list of integers L of size N. write a program to compute the value of SUM
SUM=x1pow1+x2pow2+x3pow3+-----+xNpowN
where xi concatenated with powi is the i th element of the list L and powj is single digit number
input:
The input contains space-separated N integers
Explanation: L=[25]
x1=2 ,pow1=5
SUM=2^5=32
i/p: L=[132,301]
x1=13,pow1=2
x2=30,pow2=1
SUM=13^2 +30^1=199
i/p:25
o/p:32
i/p:132 301
o/p:199
def sum(L):
X = []
pow = []
for n in L:
x = n // 10
X.append(x)
p = n % 10
pow.append(p)
s = sum_pows(X, pow)
return s
def sum_pows(X, pow):
s = 0
for x, p in zip(X, pow):
s += x**p
return s
def main():
line = input()
L = [int(s) for s in line.split()]
s = sum(L)
print(s)
if __name__ == '__main__':
main()
Comments
Leave a comment