# any help is greatly appreciated new to this stuff
"""(int, int, int, int) -> integer
Return the total number of bases covered
""" (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)
"""(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
"""(float,float) -> float # as well as for this
Return the on-base plus slugging given the on-base percentage and the slugging percentage
"""(float) -> string
Return the on-base plus slugging value given the on-base plus slugging score range
if on_base_plus_slugging > 0.9000:
elif on_base_plus_slugging > 0.7667:
elif on_base_plus_slugging > 0.7000:
else on_base_plus_slugging < 0.7000:
elif on_base_plus_slugging == 0.7000:
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.Answer2:
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
So you would calculate
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
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>