Created
August 18, 2016 18:00
-
-
Save c3h3/7a410ff657dae01327f90f84dd36e816 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from decorator_demo import logf, timeit, log | |
def my_log(filename, p, rc): | |
print 'para:'+str(p)+"\n" | |
print 'return:'+str(rc)+"\n" | |
with open("./"+filename+".log",'w') as ofile: | |
ofile.write('para:'+str(p)+"\n") | |
ofile.write('return:'+str(rc)+"\n") | |
@timeit | |
@log | |
def sum_n(n): | |
rc = n*(n+1)/2 | |
# my_log("sum_n.log", n, rc) | |
return rc | |
@timeit | |
@log | |
def sum_n2(n): | |
rc = n*(n+1)*(2*n+1)/6 | |
# my_log("sum_n2", n, rc) | |
return rc | |
@timeit | |
@log | |
def isPrime(n): | |
rc = False | |
if n > 1: | |
for i in range(2, int(math.sqrt(n))): | |
if not ((n % i) == 0): | |
rc = True | |
# my_log("isPrime", n, rc) | |
return rc | |
print "~~~~~~~~~~~~~~~~~~~" | |
sum_n(10) | |
print "~~~~~~~~~~~~~~~~~~~" | |
sum_n2("10") | |
print "~~~~~~~~~~~~~~~~~~~" | |
isPrime(57) | |
print "~~~~~~~~~~~~~~~~~~~" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment