You are on page 1of 3

#chaine de caractères

#EX1
#ex1.1
def nbrvoyelles1(CH):
    L=list(CH)
    a=L.count('a')+L.count('A')
    e=L.count('e')+L.count('E')
    i=L.count('i')+L.count('I')
    o=L.count('o')+L.count('O')
    u=L.count('u')+L.count('U')
    y=L.count('y')+L.count('Y')
    return a+e+i+o+u+y
print(nbrvoyelles1('nOmbre'))
def nbrvoyelles2(CH):
    v='aeiouyAEIOUY'
    p=0
    for i in CH.lower():
        if i in v:
            p=p+1
    return p
print(nbrvoyelles2('nOmbre'))
#ex1.2
def nbrMaj(phrase):
    p=0
    for i in phrase:
        if i.isupper()==True:#ord(A)<=ord(i)<=ord(Z)
            p+=1
    return p
#ex1.3
def nbrmots1(phrase):
    L=phrase.split()
    return len(L)
def nbrmots2(phrase):
    phrase=phrase.strip()
    s=1
    for i in phrase:
        if i==' ':#i.isspace()==True
            s+=1
    return s
print(nbrmots2('dans la classe '))

#EX2
def asterique(ch):
    L=list(ch) #L=ch.split( )
    C='*'.join(L)
    return C
print(asterique('la classe '))

#EX3
def inverser(ch):
    T=list(ch)
    L=['q']*len(T)
    for i in range(0,len(T)):
        L[i]=T[len(T)-i-1]
    c=''.join(L)
    return c
def inverser2(ch):
    if len(ch)==1:
        return ch
    else:
        return ch[-1]+inverser2(ch[:-1])
print(inverser2('window call'))

#EX4
def hamming(sh,ch):
    L=list(sh)
    T=list(ch)
    assert len(L)==len(T)
    d=0
    for i in range(len(T)):
        if L[i]!=T[i]:
            d+=1
    return d
print(hamming('sure','cure'))

#EX5
def calc_compositoin(ch):
    FA=0
    FT=0
    FG=0
    FC=0
    for i in ch:
        if i=='A':
            FA+=1
        if i=='T':
            FT+=1
        if i=='G':
            FG+=1
        if i=='C':
            FC+=1
    return ('A',FA),('T',FT),('G',FG),('C',FC)
print(calc_compositoin('ATGCTTTAGG'))
def isAnagrame(mot1,mot2):
    assert len(mot1)==len(mot2)
    mot1=mot1.lower()
    mot2=mot2.lower()
    if sorted(mot1)==sorted(mot2):
        return True
    else:
        return False
print(isAnagrame('sMsot','motss'))

You might also like