Skip to content

Instantly share code, notes, and snippets.

@MustafaAnasKH99
Created April 4, 2019 22:02
Show Gist options
  • Save MustafaAnasKH99/4842eca7f3e74fd3448bc6a80d3f1eca to your computer and use it in GitHub Desktop.
Save MustafaAnasKH99/4842eca7f3e74fd3448bc6a80d3f1eca to your computer and use it in GitHub Desktop.
Sum all numbers in a range - Mustafa Anas
# Challenge Solved in Python - Mustafa Anas
def sumAll(lst):
item1 = lst[0]
item2 = lst[-1]
summed = 0
if item2 > item1:
final_list = list(range(item1, item2+1))
for i in final_list:
summed += i
elif item1 == item2:
print('Ops! you need to have two different values!')
else:
final_list = list(range(item2, item1+1))
for i in final_list:
summed += i
#Test Me:
sumAll([7, 5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment