#๐ Find prime numbers.
10 messages ยท Page 1 of 1 (latest)
@elfin swallow
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
import random
import time
A = [random.randint(1, 10000000) for _ in range(1000000)]
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
start_time = time.time()
prime_count = sum(1 for x in A if is_prime(x))
end_time = time.time()
print(f"Number of prime numbers: {prime_count}")
print(f"Calculation time: {end_time - start_time} seconds")
Hey @elfin swallow!
It looks like you're trying to paste code into this channel.
Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
this looks suspiciously like the chatgpt code i read earlier today when i asked it to write code to check if a number is prime
did you write this?
Well this is assignment.
procedure is_prime(n) if n <= 1 then return false if n <= 3 then return true if n mod 2 = 0 or n mod 3 = 0 then return false i := 5 while i * i <= n if n mod i = 0 or n mod (i + 2) = 0 then return false i := i + 6 return true
and i should extend.
why should it be between 20-30 thousand? To me those ~66k seem right.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ Find prime numbers.