SHARE
TWEET

Untitled

a guest Jul 17th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Jul  6
  4.  
  5. @author: Jiang.Lijin
  6. """
  7.  
  8. def calc7(args):
  9.     #空白なら‐1を返す
  10.     if len(args) == 0:
  11.         return -1
  12.     ret = 0
  13.     b = 0
  14.     for n in args:
  15.         #直前の数字が7の場合はフラグ1、数字を2倍
  16.         if b == 1:
  17.             ret = ret + int(n)*2
  18.             b = 0
  19.             continue
  20.        
  21.         ret += n
  22.        
  23.         #数字が7の場合はフラグをON
  24.         if n == 7:
  25.             b = 1
  26.     return ret
  27.  
  28.  
  29. print(calc7([1, 2]))
  30. print(calc7([3, 7]))
  31. print(calc7([7, 5, 6]))
  32. print(calc7([7, 9, 7, 9, 7, 9]))
  33. print(calc7([]))
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