Python Forum

Full Version: no outcome is printing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
No list is printed because you didn't print a list. You need print calls around lines 16 and 19. Also, 'else if' in Python is 'elif':

if evenodd == "odd":
    remove_even(arr)
elif evenodd == "even":
    remove_odd(arr)
(Mar-07-2019, 02:02 PM)ichabod801 Wrote: [ -> ]No list is printed because you didn't print a list. You need print calls around lines 16 and 19. Also, 'else if' in Python is 'elif':

if evenodd == "odd":
    remove_even(arr)
elif evenodd == "even":
    remove_odd(arr)

OHH thank you so much! I appreciate it! Big Grin