Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
no outcome is printing
#1
So this is my code:

num=int(input("How many elements do you want?: "))
arr=list()
for i in range(num):
    element=int(input("Input a number: "))
    arr.append(element)
    arr.sort()
print arr

def remove_even(arr):
    return [x for x in arr if x % 2 != 0]
def remove_odd(arr):
    return [x for x in arr if x % 2 == 0]
    
evenodd=input("Would you like to sort it even or odd?: ")
if evenodd == "odd":
    remove_even(arr)
else:
    if evenodd == "even":
        remove_odd(arr)
The beginning in which the user inputs numbers works and shows up, but the part that needs help is the even/odd
part. So basically, it asks me even/odd? and I put, for example, even, but then nothing prints out. What's wrong with it? I use Codehs, but it doesn't tell me why it doesn't print.

This is just the outcome:

Output:
How many elements do you want?: 4 Input a number: 3 Input a number: 6 Input a number: 9 Input a number: 6 [3, 6, 6, 9] Would you like to sort it even or odd?: even
See? No list is printed.

Thank you if anyone responds! Blush
Reply


Messages In This Thread
no outcome is printing - by helpme - Mar-07-2019, 01:55 PM
RE: no outcome is printing - by ichabod801 - Mar-07-2019, 02:02 PM
RE: no outcome is printing - by helpme - Mar-07-2019, 02:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  outcome 0 but impossiblenumbers change bntayfur 1 1,559 Jul-05-2020, 09:05 PM
Last Post: Yoriz
  Not the expected outcome christopher3786 1 1,639 Jun-23-2020, 07:16 AM
Last Post: bowlofred
  Python program that list all possible football outcome combinations lukorir 5 9,170 Oct-17-2019, 04:05 AM
Last Post: steve_shambles

Forum Jump:

User Panel Messages

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