integer Return the total number of bases covered >>>total_bases(2,3,4,5) 40 """ return int1+2*int2+3*int3+4*int4" name="description" /> integer Return the total number of bases covered >>>total_bases(2,3,4,5) 40 """ return int1+2*int2+3*int3+4*int4" />

using the output of a function as the input in another function python new to coding


# any help is greatly appreciated new to this stuff def total_bases(int1,int2,int3,int4): """(int, int, int, int) -> integer Return the total number of bases covered >>>total_bases(2,3,4,5) 40 """ return int1+2*int2+3*int3+4*int4 def slugging_percentage(total_bases,int5): """ (total_bases, int5) -> float # so for instance i need the product of the first function for the second function Return the slugging percentage given the total number of bases covered and the total number at bat(int5) >>>slugging_percentage(20,9) 2.22 """ return total_bases/int5 def on_base_percentage(h,bb,hbp,ab,sf): """(int,int,int,int,int) -> float Return the on-base percentage given the hits, base on balls, hit by pitch, at bats and sacrfice hits >>>on_base_percentage(1,2,3,4,5) 0.43 """ return (h+bb+hbp)/(ab+bb+hbp+sf) def on_base_plus_slugging(on_base_percentage,slugging_percentage): """(float,float) -> float # as well as for this Return the on-base plus slugging given the on-base percentage and the slugging percentage >>>on_base_plus_slugging(1.0,2.0) 3.0 """ return on_base_percentage+slugging_percentage def OPS_value(on_base_plus_slugging): """(float) -> string Return the on-base plus slugging value given the on-base plus slugging score range >>>OPS_value(0.8234) B """ if on_base_plus_slugging > 0.9000: return "A" elif on_base_plus_slugging > 0.7667: return "B" elif on_base_plus_slugging > 0.7000: return "C" else on_base_plus_slugging < 0.7000: return "F" elif on_base_plus_slugging == 0.7000: return "F"


Save the variable as global is one way.

def some_function(): global var #This is a global variable #Do things to variable

The other way, which is what I believe you are looking for is to call a function inside of a function. This would look like this:

def function_1(#some variable): #Stuff could be up here num = function2(5) #Stuff could be down here def function_2(a_number): a_number = a_number*2 return a_number

This will make the variable num = 5*2.

I hope this helps.


Functions can return values. You can store those values as variables. Then you can use those values as input to other functions.

I imagine you're trying to calculate the OPS_value using on_base and slugging percentages.

So you would calculate on_base, total_bases, and slugging and store the returned values in variables.

You then pass in those variables as input to your OPS_value function, which returns the final, calculated value.

<strong>See the below example:</strong>

def OPS_value(percent): """(float) -> string Return the on-base plus slugging value given the on-base plus slugging score range >>>OPS_value(0.8234) B """ if percent > 0.9000: return "A" elif percent > 0.7667: return "B" elif percent > 0.7000: return "C" else: return "F" total_bases = total_bases(2, 3, 4, 5) # Get the return value for total_bases slugging = slugging_percentage(total_bases, 9) # Get the return value for slugging_percent on_base = on_base_percentage(1, 2, 3, 4, 5) print OPS_value(on_base + slugging) # using on_base + slugging as input

What we're trying to do is keep the math related to calculating each thing total_bases, slugging, etc separate.

The other major change from your original code is that you don't need to have a function for just adding two values. <strong>You can and should do that in one line.</strong>


  • OpenGL : Cell division effect
  • Gradle jar with jersey dependencies produces MessageBodyReader not found for media type=application/
  • I want to show two number picker using dialog
  • Weighted Average by Year in ragged data frame in R
  • How to set the the percentage format in google app script table
  • Reject or loop over user input if two conditions not met
  • Android Measure Screen in percentage
  • Dynamic Grouping in R | Grouping based on condition on applied function
  • Trying to use only a portion of a SKTexture using textureWithRect inTexture
  • How to read image field from MSSQL with PHP
  • Setting a dynamic size for an Asp:Chart control
  • Chart js shows old data on mouse hover
  • ChartKick Show original value rather percentage in PIE and line chart
  • Pivot table calculated Field from count of values
  • How can I mark as read all emails fetched through EWS in a single update?
  • Does Perl currently (5.8 and 5.10) make any promises about the order alternations will be used?
  • Cannot debug project after upgrading to Service Fabric SDK v2.3.301
  • Parse an XML fragment stored in a string into nodes in XSLT with SAXON for Java
  • html/css: how to create a hexagonal image-placeholder
  • Regex: Match everything except backreference
  • SvcUtil.exe vs Add Reference
  • Calculate area of cross-section as function of height
  • Put percent labels next to legend instead of in the slice
  • How does extglob work with shell parameter expansion?
  • C - formatting MAC address
  • How do you keep a running instance for Google App Engine
  • Custom WebViewPage inject code when razor template is rendering
  • WordPress > setting permalink option via script buggy?
  • In matplotlib, how do you change the fontsize of a single figure?
  • Rest Services conventions
  • Spring: No transaction manager has been configured
  • Elasticsearch script query involving root and nested values
  • accepts_nested_attributes_for practical form use for in Rails 3
  • Object and struct member access and address offset calculation
  • Run multiple queries from 1 SQL file showing result in multiple tables
  • Debugging ASP.NET on a built-in web server suddenly stops
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Fill an image in a square container while keeping aspect ratio
  • php design question - will a Helper help here?
  • How to get NHibernate ISession to cache entity not retrieved by primary key