[Python] check for refuel pset5 fails

Discussão em 'Python' iniciado por Stack, Dezembro 18, 2024.

  1. Stack

    Stack Membro Participativo

    I am doing refuel, a problem set in CS50p; I have restructured my fuel.py code as instructed and it has passed check 50. unfortunately my test_fuel.py code seems to fail check50 but it passed 100% when I check it as per the problem set instructions. can someone tell me what am I doing wrong?

    Here is my test_fuel.py code

    from fuel import convert, gauge
    import pytest


    def test_zero_division():
    with pytest.raises(ZeroDivisionError):
    convert("2/0")

    def test_value_error():
    with pytest.raises(ValueError):
    convert("cat/cat")


    def test_convert():
    assert convert("1/2") = 50
    assert convert("1/100") == 1
    assert convert("99/100") == 99

    def test_gauge():
    gauge(50) == "50%"
    gauge(1) == "E"
    gauge(99) == "F"


    and Here is my fuel.py code, the code that I am testing.

    def main():
    fraction = input("Fraction: ")
    f = convert(fraction)
    percent = gauge(f)
    print(percent)




    def convert(fraction):
    while True:
    try:
    numerator, denominator = fraction.split("/")
    denominator = int(denominator)
    numerator = int(numerator)
    percent = int(numerator / denominator * 100)
    if percent <= 100:
    return percent

    else:
    fraction = input("Fraction: ")
    pass

    except (ZeroDivisionError,ValueError):
    raise



    def gauge(percent):
    # tank is full
    if percent >= 99:
    return "F"
    # tank is empty
    elif percent <= 1:
    return "E"
    # tank is not full or empty
    else:
    return str(percent) + "%"


    if __name__ == "__main__":
    main()


    I wanted my test_fuel.py to pass check50; but it only pass when I test it as per the problem set instructions.

    Continue reading...

Compartilhe esta Página