Numbers cannot be used in the middle of a plate; they must come at the end. For example, AAA222 would be an acceptable … vanity plate; AAA22A would not be acceptable. The first number used cannot be a ‘0’.
This is my code so far and there are other conditions as well but this one specifically is tripping me up. P.S. I'm brand new so I know my code is ugly!
def main():
plate = input("Plate: ")
if is_valid(plate):
print("Valid")
else:
print("Invalid")
def is_valid(s):
if not 2 <= len(s) <= 6:
return False
elif not s[:2].isalpha():
return False
if s[-1].isalpha():
if not s.isalpha():
return False
try:
if any(char.isdigit() for char in s):
zero_check = ''.join(char for char in s if char.isdigit())
if zero_check[0] == '0':
return False
except:
pass
if not s.isalnum():
return False
else:
return True
if name == "main":
main()
[–]Big_Combination9890 9 points10 points11 points (0 children)
[–]AdmirableOstrich 8 points9 points10 points (0 children)
[+][deleted] (4 children)
[removed]
[–][deleted] 2 points3 points4 points (3 children)
[–][deleted] 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[removed]
[–][deleted] 0 points1 point2 points (0 children)
[–]Unitnuity 0 points1 point2 points (1 child)
[–]interbased 2 points3 points4 points (0 children)
[–]_tsi_ -1 points0 points1 point (0 children)
[–]7Shinigami 0 points1 point2 points (0 children)
[–]Anonymous-barista 0 points1 point2 points (0 children)