# Créé par Fred, le 17/02/2013 from __future__ import division from lycee import * AlphaMaj='ABCDEFGHIJKLMNOPQRSTUVWXYZ ' AlphaMin='abcdefghijklmnopqrstuvwxyz ' Alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,;:!?.éèàâêûôîçù1234567890+-=/()\'" ' Voyelles='AEIOUY' nA=26 nAl=len(Alphabet) CR='\n' def cree_chaine_alea(n,t): St='' for k in range(n): u=randint(0,nA) if t%2==0: St=St+AlphaMin[u] elif t%2==1: St=St+AlphaMaj[u] if t>=2 : St.lstrip() return St def exercice_5_6_1(n): S=cree_chaine_alea(n,0) C=0 trouve=False for k in range(n): if S[k]=='e': trouve = True; C=C+1 return trouve, C, S def exercice_5_6_2(n): S=cree_chaine_alea(n,0) print 'S=',S print 'S[0:',str(n),'+10]=',S[0:n+10] print 'S[0:',str(n),'-5]=',S[0:n-5] print 'S[',str(n),':0]=',S[n:0] print S.count(S[5:10],0,n) print S.count(S[5:10],8,n) print S.count(S[5:10],n,0) print S.find(S[5:10],0,n) print S.find(S[5:10],15,n+10) print S.find(S[5:10],n+10,2) def exercice_5_6_3(n,p): S=cree_chaine_alea(n,1) k=0 L=[] while k0: St=St+L[k-1] k=k-1 print S, CR, St def exercice_5_6_4(n,St,deb,fin): z=randint(0,n+2) S=cree_chaine_alea(z,0)+'ab'+cree_chaine_alea(n-z,0) S=S[deb:fin] k=0 trouve=False while not trouve and k0: S[k]=st+S[k] k=k+i else: k=k+1 return V.join(S) def exercice_5_6_6_c(S,p): n=len(S) k=0 trouve=False while kp if not trouve: k=k+1 S0=S.split(J) return ''.join(S0) def exercice_5_6_7_b(n,p): m=int(math.log(n)/math.log(10))+1 T=' '+(chr(151)*((m+3)*p))+CR L=range(1,n+1) S=T if n%p==0: mm=n//p else: mm=(n//p)+1 for k in range(mm): S=S+' '+chr(124) for i in range(p): z=i+p*k if z Lmax: Lmax=len(L[k]) print S, CR, L, CR, Lmax def complete_blancs(S,taille,centre): St=S if centre==0: while len(St)