Printing values of variables to the console


Hello everyone,

Sorry for the newbie question, but how do you go about printing values of variables to the console for debugging purposes? I'm currently doing the "median" lesson and I really could use some feedback...

I use the "print" instruction followed by the name of the variable (I tried it with and without parentheses), but nothing gets printed to the console...

EDIT: My code now works, but my question remains...

def median(listofnumbers):
    listofnumbers = sorted(listofnumbers)
    print (listofnumbers)
    if len(listofnumbers)%2 == 0:
        medianvalue = (lowmedian+highmedian)/2.0
    elif len(listofnumbers) == 1:
        medianvalue = listofnumbers[0]
        medianvalue = listofnumbers[len(listofnumbers)/2]
    return medianvalue

Thank you very much!



Then you did not execute that print statement. Consider this:

if False:
    print 'this will not print'

So how do you get the statements in a function to run?


I don't understand. The "print" statement isn't in a "if"...


Why not? What marks the end of the if-statement?


Line 4, "print (listofnumbers)"... That's not inside a "if"...