user1464363
user1464363

Reputation:

Invalid Syntax?

I am kindda stuck on a basic syntax error, but I can't see it. Thoughts? It's marked ### <---

This function is called through a helper file to loop while true in a main file. It runs until the error identified below.

def simulateTree():

Establish var.

    age = 0
    avg_lifespan_tree = 3
    life_expectancy = random.normalvariate(avg_lifespan_tree, 1)

Set conditional while loop

    while (age < life_expectancy):
            age = age + 0
            sigma = 1
            mu_d = .1
            d_growth = float (abs (random.normalvariate(mu_d, sigma)))
            d0 = 0
            return age

define the growth calculator

            def growth_calculate(sigma, d_growth, d0):

                    yearly_growth = age * (height_growth() + d_growth())
                    growth = 0 + yearly_growth

define the height calculator

                    def height_growth(sigma, d_growth, d0):

                            diameter = d0 + d_growth
                            b1 = .35          
                            b2 = .25
                            b3 = .35
                            e_pow = - b2 * diameter
                            e  = math.pow(math.e, e_pow)
                            e_1 = 1 - e
                            e_2 = math.pow(e_1, b3)
                            return (e_2*b1), diameter

                    h = growth_calculate(sigma, mu_d, d0)

The error is below. I attached the whole thing for context.

                    def carbon_calc(h,diameter):
                            if (diameter<11):
                                    w = .25
                                    return w
                            else (diameter>=11):   ### <---invalid syntax error here
                                    w = .15
                                    return w

                            weight_above_ground = w * diameter * diameter  * h 

                            weight_total = 1.2 * weight_above_ground
                            weight_dry =weight_total * .725
                            weight_carbon = weight_dry * .5
                            C = weight_carbon * 3.6663

                            return C

I added some superfluous text to reach the goals of stack overflow even though the question is simple and direct. It is a problem with a variably oriented design. I added some superfluous text to reach the goals of stack overflow even though the question is simple and direct. It is a problem with a variably oriented design.I added some superfluous text to reach the goals of stack overflow even though the question is simple and direct. It is a problem with a variably oriented design.I added some superfluous text to reach the goals of stack overflow even though the question is simple and direct. It is a problem with a variably oriented design.I added some superfluous text to reach the goals of stack overflow even though the question is simple and direct. It is a problem with a variably oriented design.I added some superfluous text to reach the goals of stack overflow even though the question is simple and direct. It is a problem with a variably oriented design.I added some superfluous text to reach the goals of stack overflow even though the question is simple and direct. It is a problem with a variably oriented design.I added some superfluous text to reach the goals of stack overflow even though the question is simple and direct. It is a problem with a variably oriented design.I added some superfluous text to reach the goals of stack overflow even though the question is simple and direct. It is a problem with a variably oriented design.

Upvotes: 0

Views: 319

Answers (1)

aIKid
aIKid

Reputation: 28242

You're close, what you need is not else, but elif. Change it and you are done!

Why?

Because else doesn't take a conditional argument. The code in it's block will be run when every other condition is False. Well, elif does, and that's what you want.

You can do this:

elif (diameter>=11):
     w = .15
     return w

Or:

else: #d is not < 11, so it must be >= 11
     w = .15
     return w

Reference: http://docs.python.org/2/reference/compound_stmts.html#else

Hope this helps!

Upvotes: 6

Related Questions