Tell us what’s happening:
“The number has the same digit four or more times in a row (ignoring the formatting characters).” this condition doesnt work unless i decrease it to 3 times.
Your code so far
def is_spam(number):
parts = number.split()
if not parts:
return False
country_code = parts[0][1:] # strip leading '+'
area_code = parts[1].strip("()")
prefix, line = parts[2].split("-")
# Rule 1: country code more than 2 digits or doesn't start with 0
if len(country_code) > 2 or country_code[0] != '0':
return True
# Rule 2: area code outside 200-900
if not (200 <= int(area_code) <= 900):
return True
# Rule 3: 4+ consecutive identical digits anywhere in the full number
full = country_code + area_code + prefix + line
consecutive = 0
for i in range(1, len(full)):
if full[i] == full[i - 1]:
consecutive += 1
if consecutive >= 3:
return True
else:
consecutive = 0
# Rule 4: every unique digit from country code appears in every other part
for d in set(country_code):
if not all(d in part for part in [area_code, prefix, line]):
break
else:
# All digits matched — this is the "all True" path
return True
# Rule 5: sum of prefix digits appears in line number
prefix_sum = sum(int(d) for d in prefix)
if str(prefix_sum) in line:
return True
return False
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36
Challenge Information:
Daily Coding Challenge - Spam Detector
https://www.freecodecamp.org/learn/daily-coding-challenge/09-27
GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/68b7687dded630607aceccb1.md at main · freeCodeCamp/freeCodeCamp · GitHub