Created
April 4, 2019 22:02
-
-
Save MustafaAnasKH99/4842eca7f3e74fd3448bc6a80d3f1eca to your computer and use it in GitHub Desktop.
Sum all numbers in a range - Mustafa Anas
This file contains 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
# 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