Question about function calls

6 views
Skip to first unread message

Afif Khaja

unread,
Apr 30, 2013, 9:12:48 PM4/30/13
to uic-mcs...@googlegroups.com
Hi, 
I would like to know how I can fix this sample code:

def quicksort(a):
    print a^2

def sortTime(function):
    if (function == quicksort):
        print function(5)

sortTime(quicksort)

# Should have output of 5 ^ 2 = 25 but instead the output is:
# >>>
# 7
# None
# >>>

Thanks,
Afif Khaja

Jeremy Kun

unread,
May 1, 2013, 10:21:04 AM5/1/13
to Afif Khaja, uic-mcs...@googlegroups.com
A long time ago in a galaxy far far away, we learned that ^ is not used for exponentiation, but **. The caret operator is used for something a bit more mysterious (a bitwise arithmetic operation called "xor"). 

You're seeing "None" because you're printing the result of a function which has no return statement. 

Jeremy Kun
Mathematics Graduate Student
University of Illinois at Chicago


--
You received this message because you are subscribed to the Google Groups "uic-mcs260-s13" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uic-mcs260-s1...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages