Skip to content

Instantly share code, notes, and snippets.

@sashiyama
Created July 7, 2018 00:47
Show Gist options
  • Save sashiyama/0e97009006f155911306891141558345 to your computer and use it in GitHub Desktop.
Save sashiyama/0e97009006f155911306891141558345 to your computer and use it in GitHub Desktop.
sum7.py
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