Called function not returning a value in python -
i'm relatively new python , coding in general. i've searched through of other similar questions cannot seem find answer i'm looking for. i'm working on small program calculate basketball players offensive efficiency, yet when define program , call not produce value.
def fgp(x, y): fgp = (x/y)*100 return; def fgpoutput(): x = int(input("how many shots made?")); y = int(input("how many shots attempted?")); fgp(x, y); output = "this player shooting",fgp,"%" print(output) fgpoutput() this seems work think, cannot tell because returns this:
how many shots made?5 how many shots attempted?10 ('this player shooting', function fgp @ 0x02561858, '%') i feel i've gotten close, cannot seem nail it.
ok, you've got few different issues @ play here.
- you don't return
function fgp:return;@ end offgpreturnsnone, in python, indicates absence of value. don't want that! instead, use:return fgp. - you're not calling
fgpinfgpoutput- you're printing function itself. instead, want call function this:fgp(x, y), returns calculated value. - they way construct
outputisn't quite right. in python, there's string method formatting strings include numbers:str.format(). check out documentation on here.
so, altogether get:
def fgp(x, y): fgp = (x/y)*100 return fgp def fgpoutput(): x = int(input("how many shots made?")); y = int(input("how many shots attempted?")); output = "this player shooting {} %".format(fgp(x, y)) print(output) fgpoutput() overall though, you're on right track. luck!
Comments
Post a Comment