Created
June 1, 2020 11:14
-
-
Save kurzweil777/d762f898430a40a52f4bf3f69b697140 to your computer and use it in GitHub Desktop.
Exercise_from_CodeWars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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