Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Python please need help with this code...

briank282

New Coder
so when i try running this code it says tli3 is not refernced although i made it equal to value??




import math

# trophic_level_index definition goes here

def trophic_level_index(chla, tn, tp):
""" Takes values for CHLA, TN and TP and returns
the average of the log transformed values.
"""
# complete this function.
tlc = 2.22 + 2.54 * math.log(chla,10)
tln = -3.61 + 3.01 * math.log(tn,10)
tlp = 0.218 +2.92 * math.log(tp,10)
tli3 = (tlc + tln +tlp) / 3

return(tli3)

# math.log(x, 10) will return log base 10 of x





# years_to_achieve_goal_tli3 definition goes here
def years_to_achieve_goal_tli3(c_0, tn_0, tp_0, goal_tli3, yearly_reduction):
"""fff"""
tli3 = value
year = 0
total = yearly_reduction
while value < goal_tli3:
increase = value * total
value = value - increase
year += 1
return(year)
 
The first function looks perfectly ok, but in the second function, years_to_achieve_goal_tli3, you assign the value "value" to tli3 but you never use tli3 anywhere. I guess that is what the warning is about ? The parameters c_0, tn_0, and tp_0 are not referenced either. And where does value come from anyway ? It's neither assigned or passed as a parameter. I hope you don't let your functions use variables outside its scope (or worse : modify them) ?
BTW Please post code in BBCode tags. Especially important for Python - the loss of indentation makes it impossible to see the extent of your while loop.
 

Latest posts

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom