0
How is this easy?
I’m trying to finish the Zip Code Validator challenge, but Test Case #3 doesn’t seem to budge. The prompt is basically asking to make sure that there are 5 characters, and that each are numbers. My code: zip = input() numbers = ["0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”] c = 0 for char in zip: if char in numbers: c += 1 if c == 5: print(“true”) else: print(“false”) Anybody see the issue?
4 Antworten
+ 2
...by dodgy quotation marks I mean:
Use " " : neutral, vertical, straight, typewriter, dumb, or ASCII quotation marks.
Not “ ”: typographic, curly, curved, book, or smart quotation marks.
+ 1
Update: I didn’t account for spaces.
+ 1
Your code runs, when you remove your dodgy quotes - “7” for example should be "7"
zip = input()
numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
c = 0
for char in zip:
if char in numbers:
c += 1
if c == 5:
print("true")
else:
print("false")
0
Nice catch, but I only made that mistake because when I was manually retyping my code into this post, I forgot to change the quotes.
The main issue was resolved by adding:
if char == " "
c -= 1
Under “c += 1”