Skip to content

Instantly share code, notes, and snippets.

@TomColBee
Created July 15, 2018 07:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomColBee/c88d5cd175ef1804c86695fa4b416193 to your computer and use it in GitHub Desktop.
Save TomColBee/c88d5cd175ef1804c86695fa4b416193 to your computer and use it in GitHub Desktop.
Coderbyte Python Challenge: SimpleAdding
# Have the function SimpleAdding(num) add up all the numbers from 1 to num.
# For example: if the input is 4 then your program should return 10 because 1 + 2 + 3 + 4 = 10.
def SimpleAdding(num):
sum = 0
for x in range(1,num+1):
sum = sum + x
return sum
print(SimpleAdding(input()))
# print SimpleAdding(raw_input())
# Simpler solution:
# return sum(range(1, num + 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment