Preparing git repo for final project
This commit is contained in:
39
problems/pset2/plates/plates.py
Normal file
39
problems/pset2/plates/plates.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import re
|
||||
|
||||
|
||||
def main():
|
||||
plate = input("Plate: ")
|
||||
if is_valid(plate):
|
||||
print("Valid")
|
||||
else:
|
||||
print("Invalid")
|
||||
|
||||
|
||||
def is_valid(s):
|
||||
if len(s) < 2 or len(s) > 6:
|
||||
return False
|
||||
return re.match(r"^[A-Z]{2,}([1-9]\d+)?(?![A-Z])$", s)
|
||||
|
||||
|
||||
def loopy_is_valid(s):
|
||||
length = 0
|
||||
has_digits = False
|
||||
for n, c in enumerate(s):
|
||||
if n > 6:
|
||||
return False
|
||||
if not c.isalnum():
|
||||
return False
|
||||
if n < 2 and not c.isalpha():
|
||||
return False
|
||||
if c.isdigit():
|
||||
if not has_digits and c == '0':
|
||||
return False
|
||||
has_digits = True
|
||||
elif has_digits:
|
||||
return False
|
||||
length += 1
|
||||
return length >= 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user