IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Voir le flux RSS

danielhagnoul

  1. Python. Diviser un brin d'ADN en mots de n lettres, construire un dict des mots

    par , 06/03/2020 à 21h53
    Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #! python3
    # coding: utf-8
     
     
    def compte_mots_n_lettres(brin, n):
        nb = len(brin)//n
        print('La division de la longueur du brin {} en mot de {} lettres donne {} mots.\n'.format(
            len(brin), n, nb))
        if nb*n < len(brin):
            print('Il restera {} dans le brin.\n'.format(brin[nb*n:]))
        dict_brin = {}
        mots = []
        temp = 0
        for index in range(n, len(brin)+1, n):
    ...

    Mis à jour 11/03/2020 à 18h34 par danielhagnoul (Correction, erreur de débutant, voir messages)

    Catégories
    Python , Python , Programmation
  2. Python. Compter les devises nécessaires pour payer les employés.

    par , 02/12/2019 à 19h17
    Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    #! python3
    # coding: utf-8
     
    from termcolor import cprint
    from math import trunc
     
    employes = {
        "Dupond": {
            "salaire": 4257.12,
            "composition": [],
        },
        "Durand": {
            "salaire": 2024.78,
            "composition": [],
        },
        "Pierre": {
            "salaire": 814.36,
    ...
    Tags: dict, list, round, trunc, tuple
    Catégories
    Python , Python , Programmation
  3. Python. Traduire un texte en morse et vice versa.

    par , 12/11/2019 à 19h02
    Lire les commentaires dans le code.

    Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    #! python3
    # coding: utf-8
     
    from termcolor import cprint
    import unicodedata
     
    """
    Prise en charge partielle de l'alphabet morse, voir : https://fr.wikipedia.org/wiki/Code_Morse_international
    Attention, morse_vers_texte() ne fonctionne généralement pas avec du code morse généré ailleurs.
    """
     
     
    signes = ['.-', '-...', '-.-.', '.', '..-.',
    ...
  4. Python. Convertir un nombre décimal en hexadécimal sans utiliser hex(dec)

    par , 10/11/2019 à 00h06
    Pour un débutant, cela ne me semble pas aussi simpliste que certains le disent.

    Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    #! python3
    # coding: utf-8
     
    from math import trunc
     
    # dict mapping dec -> hexa
    D2H = dict(zip(range(16), "0123456789abcdef"))
     
     
    def to_hex(n: int) -> str:
        lst = []
        while True:
            if n >= 16:
                quotient = trunc(n / 16)
                reste = n % 16
                lst.append(str(D2H[reste]))
    ...

    Mis à jour 10/11/2019 à 09h14 par danielhagnoul

    Catégories
    Python , Python , Programmation
Page 2 sur 2 PremièrePremière 12