Skip to content

Instantly share code, notes, and snippets.

@kurzweil777
Created June 1, 2020 11:14
Show Gist options
  • Save kurzweil777/d762f898430a40a52f4bf3f69b697140 to your computer and use it in GitHub Desktop.
Save kurzweil777/d762f898430a40a52f4bf3f69b697140 to your computer and use it in GitHub Desktop.
Exercise_from_CodeWars
def get_sum(a, b):
"""Given two integers a and b, which can be positive or negative, find the sum of all the numbers between
including them too and return it. If the two numbers are equal return a or b. """
if a > b: # Range function won't work if a > b, so we replacing them by each other
new_a = b
new_b = a
return sum(list(range(new_a, new_b + 1))) # Returning a sum number of all numbers in range from a to b
elif a == b:
return a | b # Returning of a or b, if numbers are equal
else:
return sum(list(range(a, b + 1))) # Returning a sum number of all numbers in range from a to b
print(get_sum(252, 525)) # 106449
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment