Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
I tried this code, but it timed out.
def count_primes_less_than(n:int) -> int:
L = 0
for i in range(2, n):
if is_prime(i):
L +=1
return L
def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
It returns correct on the tests, but when I press the attempt, it times out. Can someone help me optimize the code?
Got it
Are the test cases always going to be primes, or do I have to check for that too?
This comment is hidden because it contains spoiler information about the solution
Uh... Which part?
This comment is hidden because it contains spoiler information about the solution
I honestly have no idea how to do that. I tried a loop, but...
And.... now it gives me a TypeError, like last time.
How?
This comment is hidden because it contains spoiler information about the solution
I put in code, but when I tested it, it gave me this error:
Traceback (most recent call last):
File "/workspace/default/.venv/lib/python3.11/site-packages/codewars_test/test_framework.py", line 112, in wrapper
func()
File "/workspace/default/tests.py", line 18, in basic_test_cases
test.assert_equals(hello(nna), "Hello, World!")
^^^
NameError: name 'nna' is not defined
This is not a part of my code, it is part of the sample tests.
I put in a code, but when i tested it, it gave me this error
Traceback (most recent call last):
File "/workspace/default/.venv/lib/python3.11/site-packages/codewars_test/test_framework.py", line 112, in wrapper
func()
File "/workspace/default/tests.py", line 18, in basic_test_cases
test.assert_equals(hello(), "Hello, World!")
^^^^^^^
TypeError: hello() missing 1 required positional argument: 'name'
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution