SHARE
TWEET

Untitled

a guest Jul 17th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top