0

I want to write a function that determines whether there's an odd or even number of elements in an array.

python

def middle_element(list):
  if len(list)%2 == 0:
    return 'Even'
  else:
    return 'Odd'

However, I get --> 'function object is not subscriptable.' Thanks for reading, helping me out!

Willie Cheng
  • 7,679
  • 13
  • 55
  • 68
  • 4
    Do you have something else named `middle_element` ? – Cid Jan 28 '20 at 11:10
  • 1
    You probably have two objects both named `middle_element`. – Freeman Jan 28 '20 at 11:15
  • 1
    How do you call the function? – MisterMiyagi Jan 28 '20 at 11:20
  • Thanks for pointing that example out. Actually, I have seen that one before I wrote mine, but I thought they are different as in the other example the list was defined outside of the function and not inside the function like it was in my example. –  Jan 28 '20 at 11:22
  • Thanks MisterMiyagi! I actually called the function with square brackets instead of parantheses, which was the solution! –  Jan 28 '20 at 11:26

0 Answers0