Well, the first point i was going to make was that length variable in this line:
if length % 2 == 1:
is not the length of your list. It is the length of your list divided by two and then truncated, but for some reason it works now...
You should also sort the list, from the instructions:
For example, the median of the sequence [7,3,1,4] is 3.5, since the middle elements after sorting the list are 3 and 4 and (3 + 4) / (2.0) is 3.5
Now, lets look at your 4,5,5,4 list, after you sort, it should be 4,4,5,5 and then middle two numbers (4 and 5) should be added (9) and then divided by two. a integer (a non decimal number) divided by a integer, is a integer (the number get truncated, everything after the decimal gets thrown out of the window.
So 9 / 2 = 4. Not 4.5
Two solutions: cast it to a float using
float() function, or divide by a float (a decimal number)
In mathematics and computer science, truncation is limiting the number of digits right of the decimal point