Mar-07-2019, 01:55 PM
So this is my code:
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:
Thank you if anyone responds!
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/oddpart. 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?: evenSee? No list is printed.Thank you if anyone responds!
