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
#2
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)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  outcome 0 but impossiblenumbers change bntayfur 1 1,492 Jul-05-2020, 09:05 PM
Last Post: Yoriz
  Not the expected outcome christopher3786 1 1,559 Jun-23-2020, 07:16 AM
Last Post: bowlofred
  Python program that list all possible football outcome combinations lukorir 5 8,898 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