1

What is the problem with my code for testing plates.py?

this is the code :

def main():
    plate = input("Plate: ")
    if iss_valid(plate):
        print("Valid")
    else:
        print("Invalid")


def iss_valid(s):

    if s == 0:
        return False
    else:
        punc = [".",","," "]
        for char in punc:
            if char in s:
                return False
            break
        if not (s[0].isalpha() and s[1].isalpha) or (s[-1].isdigit() and  not(s[-2].isdigit())):
            return False
        for i in range(0,len(s)-1):

            j = i+1
            if s[i].isnumeric() and (s[j].isalpha() or s[i] == "0"):
                return False

    return True

if __name__ == "__main__":
    main()

and this is the testing or assertion code :-

from testing import iss_valid

def testing_func():
    assert iss_valid("cs05") == False
    assert iss_valid("cs50") == True
    assert iss_valid("a") == False
    assert iss_valid("asd500l") == True
    assert iss_valid("asdfasasaff") == False
    assert iss_valid("123131") == False
    assert iss_valid("asdasdsa.") == False


I am getting these errors when check50 is launched:-

:( correct plates.py passes all test_plates checks expected exit code 0, not 2 :| test_plates catches plates.py without beginning alphabetical checks can't check until a frown turns upside down :| test_plates catches plates.py without length checks can't check until a frown turns upside down :| test_plates catches plates.py without checks for number placement can't check until a frown turns upside down :| test_plates catches plates.py without checks for zero placement can't check until a frown turns upside down :| test_plates catches plates.py without checks for alphanumeric characters can't check until a frown turns upside down

2
  • 1
    The name of the function iss_valid does not match the spec. Commented Dec 8, 2023 at 10:08
  • That's fixed it. Thank you!! Commented Dec 12, 2023 at 14:30

1 Answer 1

1

As stated by DinoCoderSaurus, the name of the function iss_valid does not match the spec and should be is_valid

1
  • Thank you! That helped! Commented Dec 13, 2023 at 13:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .