mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-11 09:01:44 -04:00
Co-authored-by: Kolade Chris <65571316+Ksound22@users.noreply.github.com> Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
1.4 KiB
1.4 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 681cb1b3dab50c87ddb2e524 | Python Challenge 10: 3 Strikes | 29 | python-challenge-10 |
--description--
Given an integer between 1 and 10,000, return a count of how many numbers from 1 up to that integer whose square contains at least one digit 3.
--hints--
squares_with_three(1) should return 0.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(squares_with_three(1), 0)`)
}})
squares_with_three(10) should return 1.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(squares_with_three(10), 1)`)
}})
squares_with_three(100) should return 19.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(squares_with_three(100), 19)`)
}})
squares_with_three(1000) should return 326.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(squares_with_three(1000), 326)`)
}})
squares_with_three(10000) should return 4531.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(squares_with_three(10000), 4531)`)
}})
--seed--
--seed-contents--
def squares_with_three(n):
return n
--solutions--
def squares_with_three(n):
count = 0
for i in range(1, n + 1):
square = i * i
if '3' in str(square):
count += 1
return count