0% found this document useful (0 votes)
8 views7 pages

DL Info Chaines

Uploaded by

Ikram El
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

DL Info Chaines

Uploaded by

Ikram El
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

# __init__.

py

001| #ikram el assam mpsi 4


002| #question a
003| def longueure(TXT):
004| c = 0
005| for i in TXT :
006| c += 1
007| return c
008| #question b
009| def nombreOcurrences(x,TXT) :
010| c = 0
011| for i in TXT :
012| if x == i :
013| c += 1
014| return c
015| def miroir(t):
016| d=""
017| a=[]
018| for i in t:
019| a.append(i)
020| for j in range(len(a)-1,-1,-1):
021| d=d+a[j]
022| return d
023| a='ikram'
024| print(miroir(a))
025|
026| def miroir(t):
027| d=""
028| for j in range(len(t)-1,-1,-1):
029| d=d+a[j]
030| return d
031| a='ikram'
032| print(miroir(a))
033|
034| def supprimer_cara(txt,x):
035| txt2=''
036| a=[]
037| for i in txt:
038| if i!=x:
039| a.append(i)
040| else:
041| continue
042| for j in a:
043| txt2=txt2+j
044| return txt2
045| txt='hey yeye hehe'

1
046| print(supprimer_cara(txt,'e'))
047|
048| #exo 6
049| def alphabet(ch):
050| d=''
051| for i in ch:
052| if ord('a')<=ord(i)<=ord('z') or
ord('A')<=ord(i)<=ord('Z'):
053| d=d+i
054| else:
055| continue
056| return d
057|
058| a='salut jjjjj,.;\hkdsAAAAJKDSFFBKJDSFBajkdsh'
059| b='amd12scpspas okwpd3'
060| print(alphabetique(b))
061|
062| def moitie(ch1,ch2):
063| a=len(ch1)//2
064| b=len(ch2)//2
065| d=''
066| for i in range(a):
067| d=d+ch1[i]
068| for j in range(len(ch2)):
069| d=d+ch2[j]
070| return d
071| a='ikram'
072| b='elassam'
073| print(moitie(a,b))
074|
075|
076| #exo 8
077|
078| def premier_mot(ch):
079| d=''
080| for i in ch:
081| if i !=' ':
082| d=d+i
083| else:
084| break
085| return d
086| txt='salut, shsdkjwid dhiahqdoiqwdn'
087| print(premier_mot(txt))
088|
089|
090| #exo 9
091| def palindrome(ch):

2
092| for i in range(len(ch)):
093| a=len(ch)-1-i
094| if ch[i]!=ch[a]:
095| return False
096| return True
097| a='OTTO'
098| b='PIERRE'
099| print(palindrome(a))
100|
101| #exo 10
102| def mots(s):
103| a=[]
104| b=[' ', ',','.', ';', ':', '?', '!']
105| d=0
106| for i in s:
107| for j in b:
108| if j==i:
109| d=d+1
110|
111| else:
112| continue
113| return d
114|
115| m='salut, ikram hhhhhh'
116| print(mots(m))
117|
118|
119| #exo 4
120| def comparer(c,b):
121| a=0
122| e=min(len(c),len(b))
123| for i in range(e):
124| if ord(c[i])<ord(b[i]):
125| a=1
126| break
127| elif ord(b[i])<ord(c[i]):
128| a=2
129| break
130| else:
131| continue
132| if a==1:
133| return c,'est plus petit'
134| elif a==2:
135| return b,'est plus petit'
136| else:
137| return 'les deux ssont egaux'
138|

3
139| d='abc'
140| k='abc'
141| print(comparer(d,k))
142|
143| #exo 7
144| def convertir(ch):
145| e=''
146| l=[]
147| a='a'
148| z='z'
149| A='A'
150| Z='Z'
151| for i in ch:
152| if ord(a)<=ord(i)<=ord(z):
153| d=ord(i)-32
154| b=chr(d)
155| l.append(b)
156| elif ord(A)<=ord(i)<=ord(Z):
157| d=ord(i)+32
158| b=chr(d)
159| l.append(b)
160| else:
161| l.append(i)
162| for i in l:
163| e=e+i
164| return e
165|
166| ch='salut IKraM'
167| print(convertir(ch))
168|
169| def mots(s):
170| a=1
171| c=" ,;:.!?"
172| for i in range(len(s)):
173| if s[i] in c:
174| if i>0 and s[i-1] not in c:
175| a=a+1
176| return a
177| #l='saluT , hhh,,, ikrAm'
178| #print(mots(l))
179|
180| def codage(ch,cle):
181| a=list(ch)
182| d=''
183| for i in a:
184| b=ord(i) + int(cle)
185| d=d+chr(b)

4
186| return d
187| #print(codage('bac',3))
188|
189| def decodage(ch,cle):
190| a = list(ch)
191| d = ''
192| for i in a:
193| b = ord(i) - int(cle)
194| d = d + chr(b)
195| return d
196| #print(decodage('edf',3))
197|
198| def lissage(L):
199| M=[]
200| for i in range(len(L)):
201| if i==0 :
202| a=(L[0]+L[1])/2
203| M.append(a)
204| elif i == len(L)-1:
205| a = (L[-2] + L[-1])/2
206| M.append(a)
207| else:
208| a=(L[i-1]+L[i]+L[i+1])/2
209| M.append(a)
210| return M
211| L=[1,2,3,4,5,6,7,8]
212| #print(lissage(L))
213|
214| def meme_list(l1,l2):
215| i=len(l1)-1
216| j=len(l2)-1
217| while i>0 and j>0:
218| if l1[i] in l2 and l2[j] in l1:
219| i=i-1
220| j=j-1
221| continue
222| elif l1[i] not in l2 or l2[j] not in l1:
223| return False
224| return True
225| l1=[1,2,3,3,3,4,5,6,7]
226| l2=[1,1,1,3,3,3,4,2,5,6,7,7,7]
227| #print(meme_list(l1,l2))
228|
229| def le_plus_occurence(l):
230| d=0
231| n=[]
232| max=0

5
233| b=[]
234| for i in range(len(l)):
235| for j in range(len(l)) :
236| if l[i]==l[j]:
237| d=d+1
238| n.append(d)
239| d=0
240| for i in range(len(n)):
241| if n[i]>max:
242| max=n[i]
243| for j in range(len(n)):
244| if n[j]==max:
245| b.append(l[j])
246| e=set(b)
247| return e
248|
249| #print(le_plus_occurence(l2))
250|
251| def plus_grande_suite(chaine):
252| l=[]
253| m=[]
254| i=0
255| while i<len(chaine):
256| for j in range(i+1,len(chaine)):
257| d=1
258| if chaine[j]==chaine[i]:
259| d = d + 1
260| l.append(d)
261| m.append(i)
262| else:
263| i=j
264| a = max(l)
265| b = l.index(a)
266| c=chaine[b]
267| return a, l, b
268| a='chaaaiiiiiiiiiine'
269| print(plus_grande_suite(a))
270|
271|
272| def plus_grande_suite(chaine):
273| l=[]
274| m=[]
275| i=0
276| d=0
277| for j in range(i, len(chaine)):
278| if chaine[i]!=chaine[j]:
279| d=1

6
280| i=j
281| elif chaine[i] == chaine[j]:
282| d = d + 1
283| l.append(d)
284| m.append(i)
285|
286| a = max(l)
287| b = l.index(a)-a+1
288| c=chaine[b]
289| return a,b,c
290| a='cchaaaiiiiiiiiiinnnnnne'
291| print(plus_grande_suite(a))
292|
293|
294| def comliement_a_un(code):
295| d = ''
296| for i in range(len(code)):
297| if code[i] == '1':
298| d = d + '0'
299| else:
300| d = d + '1'
301| return d
302|
303|
304| a = '001100110'
305| # print(comliement_a_un(a))
306|
307|
308| def compliment_a_deux(code):
309| a=comliement_a_un(code)
310| d=''
311| i=len(code)-1
312| p=True
313| while i>0 and p==True:
314| if code[i]!=1:
315| i=i-1
316| else:
317| d=a[0:len(code)-1-i]+code[i::]
318| p=False
319| return d,i
320| a='10010100'
321| print(compliment_a_deux(a))

You might also like