Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. def calc7(array):
  2. # arrayの要素数が0の場合は-1を返す
  3. if len(array) == 0:
  4. return -1
  5.  
  6. sum = 0
  7. lucky = 0
  8.  
  9. for n in array:
  10. n0 = n
  11.  
  12. # nが7の直後。つまりluckyフラグが1の場合は値を2倍にする
  13. if lucky == 1:
  14. n0 = n * 2
  15.  
  16. # nの値に応じてluckyフラグを変更する
  17. if n == 7:
  18. lucky = 1
  19. else:
  20. lucky = 0
  21.  
  22. # 総和を求める
  23. sum += n0
  24.  
  25. return sum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement