Right now, i'm on a problem that prompts me to make a program based on license plates in Massachusetts, with a few conditions.
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. 4.The first number used cannot be a ‘0’.” 5.“No periods, spaces, or punctuation marks are allowed.”
Here is the code i have done so far, but it has a few problems. When i run it on check 50, i get some outputs but a majority of answers don't print anything...
:( input of CS05 yields output of Invalid Did not find "Invalid" in ""
Does anyone have any ideas why this is happening? I don't really know exactly what i did, but it may be the loops i added to fill each condition separately.
Code
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
elif s[0].isalpha() == False or s[1] == False:
return False
i = 2
while i < len(s):
if s[i].isdigit() == True:
if s[i + 1].isalpha() == True:
return False
else:
break
i = i + 1
j = 0
while j < len(s):
if s[j].isalpha() == False:
if s[j] == "0":
return False
else:
break
j = j + 1
for char in s:
if char in [" ", "?", "!", "."]:
return False
return True
main()
if, for example - and many more). You need to provide the exact code you ran, and clear examples of cases where it doesn't work as expected.