I was doing IPv4 Validator code challenge. I wrote the following code.
Your code so far
import re
def is_valid_ipv4(ipv4):
# Define the core logic exactly ONCE
num_pattern = r"([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])"
# Use an f-string to piece the full pattern together without duplication
pattern = f"^{num_pattern}\.{num_pattern}\.{num_pattern}\.{num_pattern}$"
return bool(re.match(pattern, ipv4))
Now, my code passes all the test cases given for this challenge. But there is a bug in my code. If the IP address is “192.168.1.249”, then my code returns False instead of True. So, you should modify the test cases given for this challenge. My bug fee code is as follows.
import re
def is_valid_ipv4(ipv4):
# Define the core logic exactly ONCE
num_pattern = r"([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
# Use an f-string to piece the full pattern together without duplication
pattern = f"^{num_pattern}\.{num_pattern}\.{num_pattern}\.{num_pattern}$"
return bool(re.match(pattern, ipv4))
Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.
Since my buggy code passed all the tests, it means that the issue has not been fixed as of yet. I just wanted to point it out to the people designing these tests.