Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- plate = input("Plate: ")
- if is_valid(plate):
- print("Valid")
- else:
- print("Invalid")
- def is_valid(s):
- #“… maximum of 6 characters (letters or numbers) and a minimum of 2 characters.”
- if len(s) < 2 or len(s) > 6:
- return False
- #“All vanity plates must start with at least two letters.”
- if not s[0].isalpha() or not s[1].isalpha():
- return False
- #check if there is a digit
- pos = 0
- fdp = -1
- for c in s:
- if c.isdigit():
- fdp = pos
- break
- else:
- pos = pos + 1
- if fdp != -1:
- #The first number used cannot be a ‘0’.”
- if s[fdp] == '0':
- return False
- pos = 0
- for c in s:
- if pos>fdp and s[pos].isalpha():
- return False
- pos = pos + 1
- if not s.isalnum():
- return False
- return True
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement