##### Is there a way i print odd and even numbers separately?
 Is there a way i print odd and even numbers separately? spalisetty06 Silly Frenchman Posts: 41 Threads: 18 Joined: Apr 2020 Reputation: 0 Jul-21-2020, 03:15 PM (This post was last modified: Jul-21-2020, 03:16 PM by spalisetty06.) I don't want the following output, I want the odd numbers, even numbers separately. Can you please help. ```'''odd and even numbers under 10''' for i in range(1, 11): if i % 2 == 0: print(i, " is even") else: print(i, "is odd")`````````Output:1 is odd 2 is even 3 is odd 4 is even 5 is odd 6 is even 7 is odd 8 is even 9 is odd 10 is even`````` Reply deanhystad Da Bishop Posts: 1,472 Threads: 6 Joined: Feb 2020 Reputation: 140 Jul-21-2020, 03:28 PM You could print all the even numbers then print all the odds. If you want all the evens on the same line you can print without a newline or you could join the numbers together in a single string before printing. What you cannot do is jump back and forth between lines. Reply spalisetty06 Silly Frenchman Posts: 41 Threads: 18 Joined: Apr 2020 Reputation: 0 Jul-21-2020, 05:38 PM There should be a better way than this ```'''odd and even numbers under 10''' print("even numbers") for i in range(1, 11): if i % 2 == 0: print(i, end=" ") print() print("odd numbers") for i in range(1, 11): if i % 2 !=0: print(i, end=" ")`````````Output:even numbers 2 4 6 8 10 odd numbers 1 3 5 7 9 `````` Reply deanhystad Da Bishop Posts: 1,472 Threads: 6 Joined: Feb 2020 Reputation: 140 Jul-21-2020, 05:51 PM There are better ways, but not a lot better. But what you are doing is kind of odd to start with. Slightly better way: ```print('Even numbers ', [x for x in range(0, 11, 2)]) print('Odd numbers ', [x for x in range(1, 11, 2)])```Or if you don't like the brackets: ```print('Even numbers ', ', '.join([str(x) for x in range(0, 11, 2)])) print('Odd numbers ', ', '.join([str(x) for x in range(1, 11, 2)]))``` Reply ndc85430 Da Bishop Posts: 1,241 Threads: 0 Joined: Apr 2017 Reputation: 76 Jul-21-2020, 05:52 PM What's wrong with that? How do you want to print them? Reply spalisetty06 Silly Frenchman Posts: 41 Threads: 18 Joined: Apr 2020 Reputation: 0 Jul-21-2020, 06:48 PM There is nothing wrong but does it look like a good programming way? I am learning python, I don't want to go the wrong path. Thank you. Reply

 Possibly Related Threads… Thread Author Replies Views Last Post Print max numbers in a list jimmoriarty 1 266 Sep-25-2020, 07:29 AM Last Post: DPaul Supposed to print out even numbers DallasPCMan 4 420 May-21-2020, 05:50 PM Last Post: ndc85430 first k non prime numbers print bsrohith 7 3,284 Jun-20-2019, 10:48 AM Last Post: arycloud Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 885 May-09-2019, 12:19 PM Last Post: Pleiades Why can't I print numbers in Python? skrivver99 2 1,081 Nov-04-2018, 09:47 PM Last Post: snippsat Print list from splitted range of numbers prashant8530 1 1,339 Sep-04-2017, 08:03 PM Last Post: ichabod801

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020