Skip to content

Commit

Permalink
Merge pull request #1560 from yashkumarjha12/patch-1
Browse files Browse the repository at this point in the history
Create sumofnaturalnos.py
  • Loading branch information
fineanmol authored Oct 1, 2022
2 parents 93ec9d3 + ab13435 commit ed62591
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def sumofnaturalno(num):
if num < 0:
print("Enter a positive number")
else:
sum = 0
# use while loop to iterate until zero
while(num > 0):
sum += num
num -= 1
print("The sum is", sum)

n = int(input("Enter the number to find the sum of all number till there. "))
sumofnaturalno(n)

0 comments on commit ed62591

Please sign in to comment.