This is a python program to find the sum of natural numbers
Output:
Enter a number: 10
The sum is 55
1 2 3 4 5 6 7 8 9 10 11 12 13 | # python program to find the sum of natural numbers # natural numbers up to n # where n is provided by user num = int(input("Enter a number: ")) if num <0: print("Enter a positive number") else: sum = 0 # is while loop to iterate until zero while(num>0): sum+=num num-=1 print("The sum is",sum) |
Output:
Enter a number: 10
The sum is 55
Comments
Post a Comment