Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

None???

jburns131jburns131 Posts: 1Member
I just started using python a few weeks ago. This is my first program. You input your income and what percent you want to save then it tells you how much to put away. The the code works, but it puts in the word "none" after it calls the function. Is the call sytax incorrect? I'd appreciate any feedback you could offer :-).

[code]
# savings.py 09-14-03

print "Hello, welcome to my savings program."
print
print "I will ask you a few questions then calculate"
print "the info and give you a plan of action."
print
first_name = raw_input("What is your first name? ")
print
last_name = raw_input("What is your last name? ")
print
income = input("How much do you make a year after taxes? ")
print
percent = input("What percent of your income do you want to put aside? ")
print

weekly_income = income/52

def compute(income, percent):
result = income*percent/100
print result

print "Ok,",first_name + " " + last_name
print
print "This is how much you should put away a week:"
print "$",compute(weekly_income, percent)
print
print "If you stick to this you will go places!!!"
[/code]

Comments

  • infidelinfidel Posts: 2,900Member
    : I just started using python a few weeks ago. This is my first program. You input your income and what percent you want to save then it tells you how much to put away. The the code works, but it puts in the word "none" after it calls the function. Is the call sytax incorrect? I'd appreciate any feedback you could offer :-).
    :
    : [code]
    : # savings.py 09-14-03
    :
    : print "Hello, welcome to my savings program."
    : print
    : print "I will ask you a few questions then calculate"
    : print "the info and give you a plan of action."
    : print
    : first_name = raw_input("What is your first name? ")
    : print
    : last_name = raw_input("What is your last name? ")
    : print
    : income = input("How much do you make a year after taxes? ")
    : print
    : percent = input("What percent of your income do you want to put aside? ")
    : print
    :
    : weekly_income = income/52
    :
    : def compute(income, percent):
    : result = income*percent/100
    : print result
    :
    : print "Ok,",first_name + " " + last_name
    : print
    : print "This is how much you should put away a week:"
    : print "$",compute(weekly_income, percent)
    : print
    : print "If you stick to this you will go places!!!"
    : [/code]

    This is easy. All python functions return a value. If you don't specifically say "return x", then python automatically puts a "return" at the end of your function body, which implicitly returns None (the python NULL value). Your compute function should "return result" rather than "print result".


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Sign In or Register to comment.