Overview
The code layout is good, and you used meaningful names for some functions and variables.
Documentation
You should add documentation at the top of the code as a docstring to describe its purpose:
"""
Check if license plate number is formatted correctly.
The user enters a licenses plate string, and the code reports
if it is valid or not.
"""
Indentation and spacing
There is some inconsistent indentation and spacing.
For example, the comments should be aligned with the code:
# check that all text is alpha numeric
for c in s:
The black program can be used to automatically indent and space things out for you.
Comments
Many of the comments in the code are good, but this one is not needed because you chose a meaningful name for the function:
# Get user input
plate = get_input()
You can delete that comment.
Naming
s
is not a good name for a variable. Naming it text
would be
a little more meaningful.
Prompt
The input prompt message would be more helpful if it included details to guide the user on what constitutes a valid license plate. It would also be helpful to show examples of valid and invalid plates. For example:
def get_input():
print("A valid license plate consists of:")
print(" - 2 to 6 characters")
text = input("Enter plate text:")
Invalid feedback
It would be extremely helpful to the user to see exactly why an entered plate is invalid. This would make the code longer and perhaps the valid check less efficient, but the user will be less frustrated trying to guess why it is invalid:
def is_valid(s):
# Check that plate is 2-6 characters
length = len(s)
if length < 2 or length > 6:
print(f"Must be 2-6 characters, not {length}")
return False
# starts with 2 letters.
if not s[:2].isalpha():
print(f"First"First 2 characters must be letters")
return False