Re: None shown in output

Discussion in 'Python' started by Benjamin Kaplan, Jun 22, 2012.

  1. On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis <> wrote:
    > Hello Python list,
    >
    > Noob here with a newbie question. I'm reading and working on the exerciseof
    > 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
    Benjamin Kaplan, Jun 22, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Berg

    Re: None shown in output

    Andrew Berg, Jun 22, 2012, in forum: Python
    Replies:
    0
    Views:
    195
    Andrew Berg
    Jun 22, 2012
  2. length power
    Replies:
    2
    Views:
    65
    Rustom Mody
    Apr 10, 2014
  3. Skip Montanaro
    Replies:
    0
    Views:
    48
    Skip Montanaro
    Apr 10, 2014
  4. Johannes Schneider

    Re: why i have the output of [None, None, None]

    Johannes Schneider, Apr 10, 2014, in forum: Python
    Replies:
    0
    Views:
    43
    Johannes Schneider
    Apr 10, 2014
  5. Terry Reedy
    Replies:
    0
    Views:
    53
    Terry Reedy
    Apr 10, 2014
Loading...

Share This Page