Computer Science

Write Python programs to sum the given sequences:

12 + 32 + 52 + ….. + n2 (Input n)

Python

Python Control Flow

16 Likes

Answer

n = int(input("Enter the value of n: "))

i = 1
sum = 0

while i <= n :
    sum += i ** 2
    i += 2

print("Sum =", sum)

Output

Enter the value of n: 9
Sum = 165

Answered By

6 Likes


Related Questions