I solving the vanity plates problem from CS50 online class. I writing first part of code to check that the plate number is not less then 2 characters and not more then 6. The issue is that I am getting confused by the output of if statement.
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
return True
main()
When running this code it gives me the correct output.
$ python plates.py
Plate: AAA520
Valid
$ python plates.py
Plate: AAAAAA5236
Invalid
However, when I do not include "return True" I always get "Invalid".
How is that is_valid function does not automatically return True in the case that input is more then 2 and less then 6 character and why do we need that return True? Thanks!