Q:

Check if input is all caps and numbers

I need to check if my input is all caps and numbers, it must also contain "A1" and be a multiple of 4.
def valid_product_code(string):

    #A1 must be in string
    if "A1" in string:
        val = True

    #String must be a multiple of 4
    if len(string) % 4 == 0:
        val = True

    #Must only have capitals or numbers
    if (char.isdigit() or char.islower() for char in string):
        val=True

    else:
        val = False

    return val

What am I doing wrong? When I test it, it only returns True

A:

You need to add all keyword so it will check all of the characters, change the islower to isupper and you override the return value
def valid_product_code(string):

    #A1 must be in string
    if "A1" not in string:
        return False

    #String must be a multiple of 4
    if len(string) % 4 != 0:
        return False

    #Must only have capitals or numbers
    if not all(char.isdigit() or char.isupper() for char in string):
        return False

    return True

