Answer to Question #319639 in Python for sandhya

Question #319639

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 a single digit number

i/p: the input contains space separated N integers

the o/p should be a single integer denoting SUM

L=[25]

o/p:x1=2 , pow1=5

SUM=2^5=32

i/p: 132 301

o/p:199


1
Expert's answer
2022-03-28T13:52:37-0400
def term(n):
    p = n % 10
    x = n // 10
    return x**p


def sum(L):
    s = 0
    for n in L:
        s += term(n)
    return s


def main():
    line = input()
    L = [int(s) for s in line.split()]
    print(sum(L))


if __name__ == '__main__':
    main()

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