None shown in output

Xander Solis xrsolis at gmail.com
Fri Jun 22 00:39:00 EDT 2012


Thanks for replying still! Appreciate the help.

On Fri, Jun 22, 2012 at 12:25 PM, Benjamin Kaplan
<benjamin.kaplan at case.edu>wrote:

> damn
>
> On Thu, Jun 21, 2012 at 9:24 PM, Benjamin Kaplan
> <benjamin.kaplan at case.edu> wrote:
> > On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis <xrsolis at gmail.com> wrote:
> >> Hello Python list,
> >>
> >> Noob here with a newbie question. I'm reading and working on the
> exercise of
> >> the book, Learn Python the Hard way 2.0. When I use this code, I get
> "None"
> >> on the output. My question is why does this happen?
> >>
> >> def get_numbers(first_num, second_num, operator):
> >>
> >>     if operator == 'add':
> >>         print first_num + second_num
> >>     elif operator == 'minus':
> >>         print first_num - second_num
> >>     elif operator == 'divide':
> >>         print first_num / second_num
> >>     elif operator == 'multiply':
> >>         print first_num * second_num
> >>
> >> print "%r" % (get_numbers(1, 2, 'minus'))
> >> print "%r" % (get_numbers(1+3, 2+9, 'add'))
> >> print "%r" % (get_numbers(10, 2, 'divide'))
> >>
> >> Output:
> >>
> >> C:\code\python>ex19.py
> >> -1
> >> None
> >> 15
> >> None
> >> 5
> >> None
> >> 7.5
> >>
> >> --
> >>
> >> Thanks in advance for your help.
> >>
> >> Regards,
> >>
> >> Xander
> >>
> >
> > printing something just writes the value to th
>
> I hate when I accidentally hit send early. Anyway, Michael already
> gave you the reason- print and return two different things.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120622/6e8115ea/attachment.html>


More information about the Python-list mailing list