예제 #1
0
from pourcentage import pourcent

correct = False
entier = 0

while not correct:
    correct = True
    chaine = input('Donnez un nombre écrit en base 10 :')
    try:
        entier = int(chaine)
    except ValueError:
        correct = False
        print("ce n'est pas un nombre. Essayez encore une fois.")

nombre_binaire = bin(entier)[2:]

print("Votre nombre", chaine, "contient ", pourcent(nombre_binaire),
      "pourent de 0 en base 2 (" + nombre_binaire + ").")
예제 #2
0
def test_pourcent_0():
    assert pourcent('11') == 0
예제 #3
0
def test_pourcent_1():
    assert pourcent('00') == 1
예제 #4
0
def test_pourcent_vide():
    assert pourcent('') == 0
예제 #5
0
def test_pourcent_01():
    assert pourcent('01') == approx(.5)
예제 #6
0
def test_pourcent_1():
    assert pourcent('00') == approx(1)
예제 #7
0
def test_pourcent_0():
    assert pourcent('11') == approx(0)
예제 #8
0
def test_pourcent_01():
    assert pourcent('101') == approx(1 / 3)