#!/ usr /bin/python3 # 가장 기본적인 메인 스크립트 템플릿 # by Elex (http://python.elex.pe.kr/) def main (): print ( "Hello" ) if __name__ == "__main__" : main() 파이썬 스크립트의 맨 첫 줄에는 파이썬 인터프리터의 경로를 지정한다. 현재 스크립트가 메인 모듈로써 실행되는 경우에는 __name__ 변수의 값이 "__main__"이 된다. 따라서, 이 스크립트는 메인 모듈로써 실행되는 경우에만 main() 함수를 처리하게 된다.
3과 5의 배수 1000 미만의 자연수 중, 3과 5의 배수의 합을 구하라. https://projecteuler.net/problem=1 """ Multiples of 3 and 5 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. """ if __name__ == '__main__' : s = 0 for i in range ( 1 , 1000 ): if i % 3 == 0 or i % 5 == 0 : s += i print (s)
댓글
댓글 쓰기