Created
July 7, 2018 00:47
-
-
Save sashiyama/0e97009006f155911306891141558345 to your computer and use it in GitHub Desktop.
sum7.py
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
def sum7(list): | |
if len(list) < 1: | |
return -1 | |
else: | |
count = 0 | |
for x in list: | |
if x == 7: | |
try: | |
list[count + 1] *= 2 | |
count += 1 | |
except: | |
count += 1 | |
else: | |
count += 1 | |
return sum(list) | |
# 実行例 | |
print(sum7([1, 2])) | |
print(sum7([3, 7])) | |
print(sum7([7, 5, 6])) | |
print(sum7([7, 9, 7, 9, 7, 9])) | |
print(sum7([])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment