Loading...
Loading...
Loading...
A licence server hands out prime numbers as keys. Write is_prime(n) and use it to count how many primes there are from 1 to n, including n.
Example
Input
10
Output
4
The primes are 2, 3, 5 and 7.
Try the problem first. Open one hint at a time.
Write the prime test as its own function, then call it for each number in a loop.
Keep a counter and add 1 each time the function returns True.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor