Preview:
# Program to add natural
# numbers upto 
# sum = 1+2+3+...+n

# To take input from the user,
# n = int(input("Enter n: "))

1.n = 10

# initialize sum and counter
2.sum = 0
3.i = 1

4.while i <= n:
   5. sum = sum + i
   6. i = i+1    # update counter

# print the sum
7.print("The sum is", sum)

When you run this code output will be:
Enter n: 10
The sum is 55
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter