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.

  1. you don't return function fgp: return; @ end of fgp returns none, in python, indicates absence of value. don't want that! instead, use: return fgp.
  2. you're not calling fgp in fgpoutput - you're printing function itself. instead, want call function this: fgp(x, y), returns calculated value.
  3. they way construct output isn'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

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -