[Python] cs50's python "bank testing" question is flaging the 4th condition, what is it...

Discussão em 'Python' iniciado por Stack, Março 28, 2025.

  1. Stack

    Stack Membro Participativo

    file to be tested: '''

    def main():
    use_input = input("Greeting: ").strip()
    x = value(use_input.lower())
    print(f"${x}")


    def value(greeting):
    # if greeting starts with hello , $0
    if greeting[0:5] == "hello":
    return 0

    # if greeting starts with h , $20
    elif greeting[0] == "h":
    return 20

    # else, $100
    else:
    return 100


    if __name__ == "__main__":
    main()


    ''' file which is doing the testing: '''

    from bank import value


    def test_greeting_charge():
    assert value("hello") == 0
    assert value("hi") == 20
    assert value(" ") == 100
    assert value("test") == 100
    assert value("hi where is 100th st?") == 20
    assert value("oloo") == 100
    try:
    assert value("Hi") == 20
    except AssertionError:
    print("Hi is capitalized so assertionerror")


    if __name__ == "__main__":
    main()


    ''' cs50s check output (4th condition is the concern):

    :) test_bank.py exist
    :) correct bank.py passes all test_bank checks
    :) test_bank catches bank.py with incorrect values
    :( test_bank catches bank.py without case-insensitivity
    expected exit code 1, not 0
    :) test_bank catches bank.py not allowing for entire phrase


    I really dont understand what I need to do to fix my code, pytest is working fine but the actual check for the problem fails the fourth condition

    Continue reading...

Compartilhe esta Página