Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 7, 2020 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/cafcf587898268f62290159fc2b147b2 to your computer and use it in GitHub Desktop.
Save codecademydev/cafcf587898268f62290159fc2b147b2 to your computer and use it in GitHub Desktop.
Codecademy export
#Write your function here
def middle_element(lst):
if len(lst) % 2 == 0:
index1 = int(len(lst)/2)
index2 = int(len(lst)/2 - 1)
value1 = lst[index1]
value2 = lst[index2]
average = (value1+value2)/2
return average
else:
index1 = int(len(lst)/2)
return lst[index1]
#Uncomment the line below when your function is done
print(middle_element([5, 2, -10, -4, 4, 5]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment