-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVanity Plates
More file actions
42 lines (32 loc) · 974 Bytes
/
Vanity Plates
File metadata and controls
42 lines (32 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def is_valid(s):
# Rule 1 and 2: Length must be between 2 and 6
if len(s) < 2 or len(s) > 6:
return False
# Rule 3: First two characters must be letters
if not s[:2].isalpha():
return False
# Rule 4 & 5: Only letters and numbers allowed
if not s.isalnum():
return False
number_found = False
for i, char in enumerate(s):
if char.isdigit():
if not number_found:
# First number found
number_found = True
if char == '0':
return False # First number cannot be '0'
else:
continue # We are still at the end
elif number_found:
# If a letter comes after a number, it's invalid
return False
return True
def main():
plate = input("Plate: ")
if is_valid(plate):
print("Valid")
else:
print("Invalid")
if __name__ == "__main__":
main()