Queer European MD passionate about IT

plates.py 791 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import re
  2. def main():
  3. plate = input("Plate: ")
  4. if is_valid(plate):
  5. print("Valid")
  6. else:
  7. print("Invalid")
  8. def is_valid(s):
  9. if len(s) < 2 or len(s) > 6:
  10. return False
  11. return re.match(r"^[A-Z]{2,}([1-9]\d+)?(?![A-Z])$", s) is not None
  12. def loopy_is_valid(s):
  13. length = 0
  14. has_digits = False
  15. for n, c in enumerate(s):
  16. if n > 6:
  17. return False
  18. if not c.isalnum():
  19. return False
  20. if n < 2 and not c.isalpha():
  21. return False
  22. if c.isdigit():
  23. if not has_digits and c == '0':
  24. return False
  25. has_digits = True
  26. elif has_digits:
  27. return False
  28. length += 1
  29. return length >= 2
  30. if __name__ == "__main__":
  31. main()