for x in xrange(0,21): if x%2>0: continue print x, # 0 2 4 6 8 10 12 14 16 18 20 --------------------------------------- for x in (-1,0,0,5,2,-3,4): if x>0: print x; break else: print 'Nessun elemento positivo.' # 5 for x in (-1,0,0,-5,-2,-3,-4): if x>0: print x; break else: print 'Nessun elemento positivo.' # Nessun elemento positivo. --------------------------------------- for i in xrange(4): for j in xrange(5): print i+j, print --------------------------------------- u=[[1,10],[2,10],[3,10],[4,20]] for x,y in u: print x+y, print # 11 12 13 24 v=['Aa','Bb','Cc','Dd','Ee'] for x,y in v: print y+'.'+x, print # a.A b.B c.C d.D e.E w=[[1,2,5],[2,3,6],[11,10,9]] for x,y,z in w: print x*y+z, # 7 12 119 --------------------------------------- def prodottoscalare (u,v): s=0 for x,y in zip(u,v): s+=x*y return s u=[1,3,4] v=[6,2,5] print prodottoscalare(u,v) # 32 --------------------------------------- x=0; v=[] while not x in v: v.append(x) x=(7*x+13)%17 for x in v: print x, print # 0 13 2 10 15 16 6 4 7 11 5 14 9 8 1 3 while 1: nome=raw_input('Come ti chiami? ') if nome=='': break print 'Ciao, %s!' %(nome) --------------------------------------- a=[1,2,3]; b=[11,12,13] c=[21,22,23]; d=[31,32,33] for x in zip(a,b,c,d): print x # Output: (1, 11, 21, 31) (2, 12, 22, 32) (3, 13, 23, 33) --------------------------------------- a=[1,2,3,4]; b=[11,12] c=[21,22,23,24] for x in zip(a,b,c): print x # Output: (1, 11, 21) (2, 12, 22) --------------------------------------- a=[0,1,2,3]; b=['a',7,'geo',[9,10]] c=[11,12,13,14] d=['A','B','C',['E','F']] for x in zip(a,b,c,d): print x # Output: (0, 'a', 11, 'A') (1, 7, 12, 'B') (2, 'geo', 13, 'C') (3, [9, 10], 14, ['E', 'F']) --------------------------------------- nomi=('Verdi','Rossi','Bianchi') stipendi=(2000,1800,2700) for x,y in zip(nomi,stipendi): print x,y # Output: Verdi 2000 Rossi 1800 Bianchi 2700