48. Python Program to find the Sum of n Distinct numbers.
How does this program work?
- In this program we are going to learn about how to find the Sum of n distinct numbers using Python.
- The integer entered by the user is stored in variable n.
- Declare variable 's' to store the sum of numbers and initialize it with 0.
- By using while loop we can add the sum of n distinct numbers.
Here is the code
n = (int(input("Enter distinct number till you want the sum: ")))
i = 1
s = 0
while i <= n:
s+= i #(s = s+i)
i+= 1
print("Sum of ",n, " distinct numbers is: ",s)