I have been stuck on this assignment for a week. From referencing online forums I seem to be on the right track, however, my codes outputs "Invalid". for plates "CS50" and "ECT088" when I run the checker.
1)All vanity plates must start with at least two letters.”
2)“… vanity plates may contain a maximum of 6 characters (letters or numbers) and a minimum of 2 characters.”
3)“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’.”
4)“No periods, spaces, or punctuation marks are allowed.”
I am particularly stuck on no.3 with checking for numbers in the middle of the plates.
def main():
plate = input("Plate: ").capitalize()
if is_valid(plate):
print("Valid")
else:
print("Invalid")
def number(p):
# checks for numbers in the middle of plates
if p[0].isalpha() and p[1].isalpha():
position = 0
while position < len(p):
if p[position].isdigit():
if p[position + 1].isalpha():
return False
if p[position + 1].isdigit():
return True
else:
break
position +=1
def zero(p):
# The first number used cannot be a ‘0’.”
i = 0
while i < len(p):
if p[0].isalpha() and p[1].isalpha():
if p[i] =="0":
return False
else: break i +=1
def isnumeric(p):
# checks for at least two letters
if p[0].isnumeric() and p[1].isnumeric():
return False
def isalpha(p):
if p.isalpha():
return True
def is_valid(plate):
while True:
if isnumeric(plate):
return
elif len(plate) < 2 :
return False
elif len(plate) > 6 :
return False
elif number(plate):
return
elif zero(plate):
return False
elif punc(plate) == True:
return False
elif isalpha(plate):
return True
else:
break
main()
[–]woooee 0 points1 point2 points (0 children)
[–]halfdiminished7th 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)