File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -175,3 +175,52 @@ n = int(input("Enter the value of number: "))
175175print (sumofcubes(n))
176176
177177```
178+ #### Sum of squares of natural numbers
179+
180+ ``` python
181+ # Method 1
182+ # Return the sum of square of first n natural numbers
183+ def squaresum (n ) :
184+ # Iterate i from 1 and n finding square of i and add to sum.
185+ sum = 0
186+ for i in range (1 , n+ 1 ) :
187+ sum = sum + (i * i)
188+ return sum
189+ n = int (input (" enter the value of n : " ))
190+ print (squaresum(n))
191+
192+
193+ # method 2
194+
195+ # # n * (n + 1) * (2 * n + 1)/6
196+ def sumofsquares (n ):
197+ sum = n * (n + 1 ) * (2 * n + 1 ) // 6
198+ return sum
199+
200+ n = int (input (" enter the value of n : " ))
201+ print (sumofsquares(n))
202+ ```
203+
204+ #### Remove punctuation from string
205+ ``` python
206+ # Removing punctuations in string
207+ # Using regex
208+ import re
209+
210+ # initializing string
211+ test_str = " python, is best program: to learn !!!;"
212+
213+ # printing original string
214+ print (" The original string is : " + test_str)
215+
216+ # Removing punctuations in string Using regex
217+ res = re.sub(r ' [^ \w\s ]' , ' ' , test_str)
218+
219+ # printing result
220+ print (" The string after punctuation filter : " + res)
221+
222+ # output :
223+ The original string is : python, is best program: to learn !!!;
224+ The string after punctuation filter : python is best program to learn
225+
226+ ```
You can’t perform that action at this time.
0 commit comments