Mar-28-2018, 03:23 AM
I know this is something so simple that I'm missing but I can't figure it out. I'm in first year Python and we've been tasked with setting up a hypothetical student database. One of the requests is for the student to enter their postal code. Our program is to check that it's 6 digits long and that its letter/digit/letter/digit/letter/digit. There's no exception raised, but it always says Congrats even if I put in all digits.
Thanks for your help -
Jude
Here is my code:
Thanks for your help -
Jude
Here is my code:
def main(): valid=True while valid: PostalCode=input("Enter postal code, no spaces: ") if checkCode(PostalCode): valid=False else: print("Error, please try again. 6 digits, no spaces ") print(PostalCode, "Congrats, you solved it.") def checkCode(spost): codelength=len(spost) if codelength==6 and spost[0:5:2].isdigit and spost[1:5:2].isalpha: return True else: return False main()