0
I’m trying to do the zip code validator code coach. My code works for test cases 2-5 but not for 1 and 6. Please help!
Everything seems to be outputting false and I can’t figure out what I’m missing. Here’s my code: https://sololearn.com/compiler-playground/cxvNx1ViYz3M/?ref=app
2 ответов
+ 1
As case 6 is locked I cannot be sure, but let’s take a look on case 1.
Case 1 input: '52452'
After line 1 is executed, x become ['52452’].
It is a list with length of one, therefore line 7 evaluates it to True, and print 'false' on screen.
As a side note, your program is over complicated.
The description says the length of the zipcode "must be 5 characters in length".
You can use not equal operator != to do the checking.
The way you code x becomes a list. However list doesn't have isspace() method, it is a string method. It might be the cause make your code cannot pass case 6.
Remember string is a "list of characters." You don't have to make alpha into a list.
Also the description says zipcode only contains numbers, an alternative is to check for each character in zipcode contains number or not.
+ 1
Another tips.
You can always put a print() statement in the middle of your code to see what your code is doing. Such as:
print("DEBUG", some variable or condition)
Once you get the result you want, you can comment out the line and put your code into test.