0

I would just like a tip on how to send even numbers to the left and odd numbers to the right, I've been trying for a long time and I can't, the subject is composed lists, I appreciate any help. Simplified code below without loop or conditional structure.

test = [[],[]]

num = int (input("Type it : "))

test.append()

print(test)
khelwood
  • 55,782
  • 14
  • 81
  • 108
  • Your question could (should) be much more focused. With what exactly are you struggling? As I see it, you need to take input of a number, check if it is even or odd and then add it to a certain list. With which part do you need help? *"I've been trying for a long time and I can't"* - judging by the code here, you didn't try so much. Please show an honest effort of solving your own problem and ask about ***that***. Remember that is not a coding service – Tomerikoo May 28 '21 at 13:08

1 Answers1

0
test = [[], []]
num = input("Enter a number or quit")
while num != "quit": # execute code as long as num is not quit
    num = int(num) # convert num to a number (until here, it's a string !!!)
    if num % 2 == 0: # num is even
        test[0].append(num)
    else: # num is odd
        test[1].append(num)
print(test)
TheEagle
  • 5,808
  • 3
  • 11
  • 39
  • 2
    Notice your `if` condition and what you do in it. This can just be `test[num % 2].append(num)`. No condition needed – Tomerikoo May 28 '21 at 13:02
  • @Tomerikoo good point, but I want to leave my code as it is, because your solution is hard to understand for a beginner - "adds something useful to the post" though ! – TheEagle May 28 '21 at 13:03
  • @Programmer Please try to avoid answering questions that ask for (what seems to be) homework solutions. This helps no-one. OP doesn't gain anything from it (they are meant to do it by themselves to learn...). Stack Overflow is not meant for getting HW solutions. It is meant for programming questions that will help others in the future. – Tomerikoo May 28 '21 at 14:53