a=range(5,13,2) print a a=range(5,13) print a a=range(11) print a --------------------------------------- a=xrange(5,13,2) print a for x in a: print x, --------------------------------------- if 3<5<9: print 'o.k.' a=b=c=4 for x in [a,b,c]: print x, print --------------------------------------- def f(x): return 2*x+1 def g(x): if (x>0): return x else: return -x for x in xrange(0,10): print f(x), print for x in xrange(-5,5): print g(x), print --------------------------------------- import math def raggio (x,y): return math.sqrt(x**2+y**2) print raggio(2,3) print math.sqrt(13) --------------------------------------- def sommax (f,g,x): return f(x)+g(x) def compx (f,g,x): return f(g(x)) def u(x): return x**2 def v(x): return 4*x+1 print sommax(u,v,5) print compx(u,v,5) --------------------------------------- def somma (f,g): def s(x): return f(x)+g(x) return s def comp (f,g): def c(x): return f(g(x)) return c def u(x): return x**2 def v(x): return 4*x+1 print somma(u,v)(5) print comp(u,v)(5) --------------------------------------- print 'Carlo era bravissimo.' print "Carlo e' bravissimo." print '''Stringhe a piu' righe si usano talvolta nei commenti.''' --------------------------------------- def somma (*a): s=0 for x in a: s+=x return s print somma(1,2,3,10,5) --------------------------------------- def horner (alfa,*a): alfa=float(alfa); b=0 for t in a: b=b*alfa+t return b print horner(10,6,2,0,8) --------------------------------------- latino = {'casa': 'domus', 'villaggio': 'pagus', 'nave':'navis', 'campo':'ager'} voci=sorted(latino.keys()) for x in voci: print '%-9s = %s' %(x,latino[x]) --------------------------------------- a=5; b=3; a,b=b,a; print [a,b]