#π Can someone help me fill in the numbers?
45 messages Β· Page 1 of 1 (latest)
@novel hollow
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.
number = 1842
if number == 0:
print("Even")
if number == 1:
print("Odd")
if number == 2:
print("Even")
if number == 3:
print("Odd")
if number == 4:
print("Even")
if number == 5:
print("Odd")
if number == 6:
print("Even")
if number == 7:
print("Odd")
if number == 8:
print("Even")
if number == 9:
print("Odd")
if number == 10:
print("Even")
if number == 11:
print("Odd")
if number == 12:
print("Even")
if number == 13:
print("Odd")
if number == 14:
print("Even")
if number == 15:
print("Odd")
if number == 16:
print("Even")
if number == 17:
print("Odd")
if number == 18:
print("Even")
if number == 19:
print("Odd")
if number == 20:
print("Even")
if number == 21:
print("Odd")
if number == 22:
print("Even")
if number == 23:
print("Odd")
if number == 24:
print("Even")
if number == 25:
print("Odd")
if number == 26:
print("Even")
if number == 27:
print("Odd")
if number == 28:
print("Even")
if number == 29:
print("Odd")
if number == 30:
print("Even")
if number == 31:
print("Odd")
if number == 32:
print("Even")
if number == 33:
print("Odd")
if number == 34:
print("Even")
if number == 35:
print("Odd")
if number == 36:
print("Even")
if number == 37:
print("Odd")
if number == 38:
print("Even")
if number == 39:
print("Odd")
if number == 40:
print("Even")
if number == 41:
print("Odd")
if number == 42:
print("Even")
if number == 43:
print("Odd")
if number == 44:
print("Even")
if number == 45:
print("Odd")
if number == 46:
print("Even")
if number == 47:
print("Odd")
Just to double check: Are you serious or is it a joke ?
yep
AI could probably help with this
% returns the remaining of the integer division
Or write a function to write the function
ahhh
it could, but you should'nt use it for that
yep
ok ty
I asked this bc it is a regular joke in the field, nothing personal
oh ok, i just never knew about that
even thought of coding more if clauses with an algorithm
repeting the (nearly) same line/block of code usually means you can do it more efficiently
At least with a loop and a function, or even with just like a different algorithm
yep, the modulo operator returns the remainder. if you divide 1 with 2, the remainder would be 1, and not 0, for example.
genius
can you not insult people ?
actually, this code is bad because its only up to 47 numbers and users cant send numbers higher like 500 or something
i would recommend you to do this instead
https://paste.pythondiscord.com/KZWQ
it's normal for a beginner to make mistakes, not knowing how to use features and making bad algorithms. That's why you learn
Did you even read the conversation ?
or is it a joke ?
isnt that obvious
it's not
i wouldnt waste my time writing 1k lines of code, so thats definitely a joke
perhaps people should focus on being helpful or being silent
Insulting peoples intelligence is not appropriate. if you don't want to give this person the benefit of the doubt, just don't engage with the thread.
I'm sorry ._.
I won't do this again
there are other ways
like you can use // (integer division)
# checks if rounding down is the same as halfing thus checking if the half is an integer
x//2 == x/2
# same as:
floor(x/2) == x/2
#but floor has to be imported from math
or recursion
# recursion is the fact that a function can call itself, in this case that's done in 2 steps
# as a bonus here you get bot is_even and is_odd
def is_even(x: int) -> bool:
if x == 0:
return True
return is_odd(x-1)
def is_odd(x: int) -> bool:
if x == 0:
return False
return is_even(x-1)
or loops can do it similarly as you did just for bigger numbers
# your method: counting up and checking if equal
n = 0
is_even = True
while n != x
is_even = not is_even
n += 1
or replicate the recursion with loops
# recursion method: counting down checking if 0
is_even = True
while x != 0:
is_even = not is_even
x -= 1
there are ways with binary operations
x >> 1 << 1 == x
# or
bool(x & 1) # need bool() because the result is 0 or 1
there are a lot of funny ways
some of them show different tools
but most of them are way slower and more complicated than needed
not x%2 # don't need bool() beacuse not a is the same as not bool(a)
is the most used i think
here is an other joke method
def is_even(x: int) -> bool:
return not is_odd(x)
def is_odd(x: int) -> bool:
return not is_even(x)
which is funny because it never finishes and symbolizes people trying to get others to do their tasks resulting in those tasks never getting done
num = input(">> ")
result = "Even" if int(num) % 2 == 0 else "Odd"
print(result)```
how bout this
ofc thats the best way
i just thought op already got that one from yall didnt he?
*Math
sorry
This help channel has been closed. 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.