Answer to Question #293913 in Python for rahul

Question #293913

Write a python function Sum(x) which takes a comma-separated string of numbers and returns the reverse of the sum of the smallest and largest numbers in the given list as shown in example. For ex , for the list 10,28,43,52 the sum of smallest and largest numbers is 62 and the reverse is 26. Write a separate recursive function Reverse-Sum(n)

to compute the reverse of a number and call this function inside the Sum(x). Do not use

input() function, specify the input in fixed form.


1
Expert's answer
2022-02-04T07:59:21-0500

def Sum(s):

    L = [ int(w) for w in s.split(',') ]

    xMin = L[0]

    xMax = L[0]


    for x in L:

        if x < xMin:

            xMin = x

        if x > xMax:

            xMax = x

   

    sum = str(xMax + xMin)

    r_sum = ReverseSum(sum)

    return int(r_sum)


def ReverseSum(s):

    if len(s) <= 1:

        return s

    sub_s = s[1:-1]

    res = s[0] + ReverseSum(sub_s) + s[-1]

    return s


def main():

    x = Sum('10,28,43,52')

    print(x)


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