Skip to content

Commit 983ad4d

Browse files
committed
Create sum of sqaures of n natural numbers
This find the sum of n natural numbers
1 parent 84e9378 commit 983ad4d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#find sum of n natural numbers
2+
class sum_of_squares:
3+
def get_square_of_series(self,n):
4+
self.n=n
5+
if n>0:
6+
r=(n*(n+1)*((2*n)+1))/6
7+
print(f"The sum of squares of the first {n} natural numbers is {r}")
8+
else:
9+
print("Kindly enter a natural number!")
10+
11+
12+
13+
solution1=sum_of_squares()
14+
a=int(input("Enter a natural number to find sum of sqaures upto that number:"))
15+
solution1.get_square_of_series(a)

0 commit comments

Comments
 (0)