print math.degrees(math.atan2(1,0)) # 90 print math.degrees(math.atan2(1,-1)) # 135.0 print math.degrees(math.atan2(-1,-1)) # -135.0 --------------------------------------- for x in (90,135,180,270,360): print math.radians(x) # Output: 1.57079632679 2.35619449019 3.14159265359 4.71238898038 6.28318530718 for x in (1.6,2.4,3.1,4.7,6.3): print math.degrees(x) # Output: 91.6732472209 137.509870831 177.616916491 269.290163711 360.963410932 --------------------------------------- for x in (0,1,2,math.log(7)): print math.exp(x), # 1.0 2.71828182846 7.38905609893 7.0 print print math.ldexp(1,6) # 64.0 print math.ldexp(2.5,6) # 160.0 for b in (2,math.e,7,10): print round(math.log(10,b),4), # 3.3219 2.3026 1.1833 1.0 print math.log(1024,2) # 10.0 --------------------------------------- for x in (-1.3,-4,0.5,2,2.7): print math.floor(x), math.ceil(x) # Output: -2.0 -1.0 -4.0 -4.0 0.0 1.0 2.0 2.0 2.0 3.0 --------------------------------------- print math.e # 2.71828182846 print math.pi # 3.14159265359 --------------------------------------- for k in xrange(1,8): print cmath.sin(k*math.pi*1j) # Output: 11.5487393573j 267.744894041j 6195.82386361j 143375.656567j 3317811.99967j 76776467.6977j 1776660640.42j --------------------------------------- def somma (*a): s=0 for x in a: s+=x return s v=[1,2,4,9,2,8] s=apply(somma,v) print s # 26 --------------------------------------- def f(x,y): return (x+y)/2.0 print reduce(f,[3]), print reduce(f,[3,4]), print reduce(f,[3,4,5]), print reduce(f,[3,4,5,8]) # 3 3.5 4.25 6.125 --------------------------------------- def hornerr (a,x): def f(u,v): return x*u+v return reduce(f,a,0) a=[7,2,3,5,4] print hornerr(a,10) # 72354 --------------------------------------- def frazcont (v): def f(x,y): return y+1.0/x w=v[:]; w.reverse() return reduce(f,w) print frazcont([2,3,1,5]) # 2.26086956522 = 52/23.0