3

The code below is from hackermeter.com and I'm not sure what to think of it. Is the variable i being passed implicitly to run() or does it expect more modification than just where it specifies?

import sys

def run():
   # Code here!

for i in range(int(sys.stdin.readline())):
   run()
4

2 に答える 2

10

これは不適切なコーディング手法であると私は主張します。run()アクセスできる唯一の理由iは、それiがグローバルであることです。

i以下は、プログラマーにrun()明示的に渡すことを強制するため (必要な場合) 、間違いなく優れています。

import sys

def run():
   # Code here!

def main():
   for i in range(int(sys.stdin.readline())):
      run()

if __name__ == '__main__':
   main()
于 2013-08-28T14:20:08.547 に答える