# Gosh ok i have no idea how to use the fourms but im having trouble with a thing

#1

’ ’ ’

``````def median(list):
big_thorst = [sorted(list)]
bigger_thorst = len(big_thorst)
if bigger_thorst %2 == 0:
even_bigger_thorst = ((bigger_thorst / 2) + ((bigger_thorst / 2)+1)) / (2.0)
else:
even_bigger_thorst = (bigger_thorst / 2) + 1
biggest_thorst = big_thorst[even_bigger_thorst]
return biggest_thorst
``````

’ ’ '
all right someone please its supposed to give me the median but its giving me a “list index out of range” error?? also please ignore the terrible names i was bored and i dont want to change it cause it gets a reaction from my friends ok thanks sorry OH I FORGOT TO SAY ITS PYTHON AND IM VERY LOST ON HOW TO USE THE FORUMS

#2

here:

``````biggest_thorst = big_thorst[even_bigger_thorst]
``````

the `even_bigger_thorst` contains the median value, why would you use it as index?

There is a new user section on the forum:

maybe that helps

#3

oh uh

``````def median(list):
big_thorst = [sorted(list)]
bigger_thorst = len(big_thorst)
if bigger_thorst %2 == 0:
even_bigger_thorst = ((bigger_thorst / 2) + ((bigger_thorst / 2)+1)) / (2.0)
else:
even_bigger_thorst = (bigger_thorst / 2)
biggest_thorst = even_bigger_thorst
return biggest_thorst
``````

median([1]) returned 0 instead of 1

#4

i missed something, look at this code:

``````def median(list):
big_thorst = [sorted(list)]
print big_thorst
bigger_thorst = len(big_thorst)
if bigger_thorst %2 == 0:
even_bigger_thorst = ((bigger_thorst / 2) + ((bigger_thorst / 2)+1)) / (2.0)
else:
even_bigger_thorst = (bigger_thorst / 2)
biggest_thorst = even_bigger_thorst
return biggest_thorst

print median([1])
``````

i added a function call, this way, we can insert print statement in the function, to see values of variables, isn’t that nice? I took the liberty to add a print statement within the function, to see the value of `big_thorst`, which seems to be a 2d list, why would you want that? 1d (d=dimension) should be enough

#5

thank you very much for taking time to help me but i am going to be frustrating in saying: wait what whats thedifference between 2d and 1d in this context

#6

good question.

we can nest a list within a list:

``````[[3],[4]]
``````

this is known as a two dimensional list, one or more list within a list. we can even make 3d or 4d (d=dimensional) list. Do you think you can picture that?

so this:

``````[5]
``````

would be one dimensional list.

if we have a 2d list:

``````x= [['a']]
``````

we would need to do:

``````print x[0][0]
``````

to print `a`

you also have a 2d list, and i don’t see the added value in your program

#7

oh ok so the `big_thorst = [sorted(list)]` bit is the nested part?? how do i unnest it cause i just need the list to be sorted and yeahh but if i take the brackets off it says its a float and it doesnt like thsat actually hold on im gonna see if i can get a picture into here

ok there we go

#8

`sorted()` will return a list, by putting `[]` around it, you get the 2d list you didn’t want

looking at your image, you solved that, but now we circle back to an earlier problem:

#9

uhhhhhhhhhhhhhhhidontknow uh returns 0 instead of 1 but then i put the +1 back so:

#10

for `[4, 5, 5, 4]` we need to sort the list, which you do fine. Then we need to get the left and right middle value. You only get the left and right middle index, you never use the indexes to retrieve the values from the list

#11

how and where do i do that

#12

well, `bigger_throst / 2` gives the right middle index, to get the value from `big_thorst` list, use the index.

to get values from a list using index, use the square brackets, general syntax:

``````your_list[index]
``````

for example:

``````x = ['a']
print x[0]
``````

in your case, you can use `bigger_throst / 2` as index. Yes, we calculate an index and then use it

#13

oh thats what i was trying to do with `biggest_thorst = bigger_thorst[even_bigger_thorst]` ok hh

``````def median(list):
big_thorst = sorted(list)
print big_thorst
bigger_thorst = len(big_thorst)
if bigger_thorst %2 == 0:
even_bigger_thorst = (big_thorst[bigger_thorst / 2] + (big_thorst[bigger_thorst / 2)+1]) / (2.0)
else:
even_bigger_thorst = [bigger_thorst / 2] +1
biggest_thorst = even_bigger_thorst
return biggest_thorst
print median([1])
``````

#14

I fail to see the value of using variable names with no meaning that only serve to confuse the reader, even one’s self. Simple variable names that describe what they are is better all around.

``````s = sorted(list)
``````

Which brings us around to using reserved words as variable names. `list` is a reserved word, a function in global scope. If you were to try to use the list function in the context of your function, it might not work, since locally, `list` is not a function. Avoid using reserved words for variable names or you could find yourself looking for bugs that are hard to find.

``````def median(sample):
s = sorted.sample
``````

`median` is a concept relating to statistics. There are two kinds of statistical collections… Census, and sample. When all the data in a census is collected and used in an analysis, it is called the census data. When only a sampling, or subset of the collection is used, it is called a sample. In terms of median, either term would be reasonable to use as the parameter name since they both describe roughly the same thing… A collection of data points.

In programming, the language we use in our code should speak to the concepts to which they relate, not be some made up term that means nothing to anybody, and may be perhaps a joke to the writer that nobody catches on to since the punch line is in the writer’s head. If you really want to be a programmer, then start by learning how to name variables so they mean what they are supposed to mean. Variables are for human readers, not the computer.

``````bigger_thurst = len(big_thurst)
``````

versus,

``````n = len(s)
``````

Using meaningless names adds to the verbosity and creates bloat where none is needed. It makes reading almost painful and does not paint a clear picture of the purpose of the function and its expected returns.

#15

i named the things when i was tired and i couldnt stop thinking of a post i saw on tumblr also it told me to use list please dont complain about how i do this i just want it to give me the number

#16

That’s not complaining, but offering up advice. You can choose to ignore it or make excuses but it doesn’t change anything.

Then sort out your code so it makes sense to read and you might find it easier to discover errors or omissions.

#17

bud i just want to be done with this please

#18

OK EVERYONE CAN GO HOME I GAVE UP AND CLICKED GIVE CODE . a

#19

And what did you learn from the Get Code? The easy way out?

#20

dude friend bud why are you so passive agressive im 14 i dont need this in my life im already mildly depressed why do you have to drag people down with you