[Solved] Develop a function in python to generate and sum the following series

Develop a function in python to generate and sum the following series x+x*y+(x*y)2+(x*y)3++(x)n

Supply x, y, n as inputs to the function. Do not use any library functions, use loops and other basic

structures.

Solution

def series(x, y, n):
    l = []
    l.append(x)
    for i in range(1, n):
        l.append(x*y*i)

    #sauravhathi
    for i in l:
        print(i, end=" ")
    print()
    return sum(l)


x = int(input("Enter the first number: "))
y = int(input("Enter the second number: "))
n = int(input("Enter the number of terms: "))
print(series(x, y, n))

Output:

Enter the first number: 1
Enter the second number: 2
Enter the number of terms: 6
1 2 4 6 8 10 
31

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *