#๐Ÿ”’ Some questions about the simple code

12 messages ยท Page 1 of 1 (latest)

trim pivot
#

ok so I'm trying to make a function that when u enter an integer, it'll return all prime numbers under it using the eratosthene.

few questions: why prime_num = [True] * n needs to be timed with n? I'm assuming that'll mean you'll be printing as many trues in a list as the number of the input

and for the line for i in range (j*j,n,j):, why is it not possible to change the upper bound to be n+1, I'm trying to ake the function inclusive of the input, not exclusive

glad rivetBOT
#

@trim pivot

Python help channel opened

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.

trim pivot
#

oh and for more context, if I use n+1, sometime's it'll be fine, sometimes it'll say
list assignment index out of range

shadow forum
polar thorn
polar thorn
polar thorn
glad rivetBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

polar thorn
#

!code if it's short like the one you had now

glad rivetBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

glad rivetBOT
#
Python help channel closed

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.