Skip to content

Instantly share code, notes, and snippets.

@computer-tutor
Created April 28, 2020 04:25
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save computer-tutor/7b8e6407e028858bafda89d6ee37efb6 to your computer and use it in GitHub Desktop.
n = int(input("Enter an Integer: "))
x = 0
if n > 0:
for i in range(n, 2*n+1):
x += i
else:
for i in range(2*n, n+1): # for negative n, we need to reverse start & end of range
x += i
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment