python - Why is this returning an extra none? -


def hotel_cost(nights):     return nights * 140  bill = hotel_cost(5)  def add_monthly_interest(balance):     return balance * (1 + (0.15 / 12))  def make_payment(payment, balance):      new_balance2 = balance - payment     new_balance = add_monthly_interest(new_balance2)     print "you still owe: " + str(new_balance)  make_payment(100,bill) 

why return

you still owe: 607.5 none 

?

it doesn't return that. returns none, because that's function returns if don't have return statement.

meanwhile, prints out "you still owe: 607.5", because that's what's in print statement.

(by "it" here, i'm assuming you're referring function call make_payment(100, bill).)

my guess you're running inside ide or other interactive session that's printing out return value of each statement. so, code prints "you still owe: 607.5", , interactive interpreter prints "none".

the default python interactive interpreter (like ipython , bpython , many others) swallow none returns instead of printing them out. whichever 1 you're using presumably doesn't that.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -