0

according to the pset instructions a number must come at the end and a number can't be used in the middle of a plate; surprisingly check passed CS50P as valid(expected invalid) and CS50P2 as invalid. Moreover, my if statement sliced a plate from the first occurrence of a digit to the end of a plate and check if it is a digit; with this statement I was expecting any character that appear after the first occurrence of a digit should be a digit else the plate will be invalid, sadly it is not what I get.

Here is my code

def main():
    # prompt the user for input; trip it
    plate = input("Plate: ")
    # check validity of the input
    if is_valid(plate):
    # print valid or invalid
        print("Valid")
    else:
        print("Invalid")


def is_valid(s):
    # check if is alphanumeric, check length and check atleast first two characters are alphabetic
    if s.isalnum() and 2 <= len(s) <= 6 and s[0:2].isalpha():
        i = 0
        while i < len(s):
            #check if first is "0"
            if s[i].isdigit():
                if s[i] == "0" or s[i:len(s) - 1].isdigit() == False:
                    return False
                else:
                    break

            i = i + 1
        return True
    else:
        return False


main()

My check50 passed perfectly but I wasn't expecting CS50P to pass as valid and CS50P2 passed as invalid (as expected).

Balup
  • 5
  • 5

0 Answers0