Thanks Andrew and Michael!. That did the trick.<br><br>def get_numbers(first_num, second_num, operator):<br> <br> if operator == 'add':<br> value = first_num + second_num<br> elif operator == 'minus':<br>
value = first_num - second_num<br> elif operator == 'divide':<br> value = first_num / second_num<br> elif operator == 'multiply':<br> value = first_num * second_num<br> <br> return value<br>
<br>print "%r" % (get_numbers(1, 2, 'minus'))<br>print "%r" % (get_numbers(1+3, 2+9, 'add')) <br>print "%r" % (get_numbers(10, 2, 'divide')) <br><br>output:<br>
<br>-1<br>15<br>5<br><br><div class="gmail_quote">On Fri, Jun 22, 2012 at 12:23 PM, Andrew Berg <span dir="ltr"><<a href="mailto:bahamutzero8825@gmail.com" target="_blank">bahamutzero8825@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 6/21/2012 10:42 PM, Xander Solis wrote:<br>
> Hello Python list,<br>
><br>
> Noob here with a newbie question. I'm reading and working on the<br>
> exercise of the book, Learn Python the Hard way 2.0. When I use this<br>
> code, I get "None" on the output. My question is why does this happen?<br>
</div>Your function prints the number and then returns None (you have no<br>
return statement in the function to change this) to the print statement.<br>
If you want to have the function return a value, use the return<br>
statement instead of print inside the function:<br>
<br>
def func(some_value):<br>
return some_value<br>
x = func(5)<br>
print x<br>
<br>
will print 5.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
CPython 3.3.0a4 | Windows NT 6.1.7601.17803<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br>