#!/usr/bin/env python # *-# -*- coding: utf-8 -*- #1 print 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 #2 def f2(n): arr = range(1, n + 1) return sum(arr) print f2(10) #3 def f3(n): return (n * (n + 1)) / 2 print f3(10)
結果
55 55 55
牌語備忘録 -pygo
#!/usr/bin/env python # *-# -*- coding: utf-8 -*- #1 print 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 #2 def f2(n): arr = range(1, n + 1) return sum(arr) print f2(10) #3 def f3(n): return (n * (n + 1)) / 2 print f3(10)
55 55 55