Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Logic in Python Try and Except

Seamus Hannan
Seamus Hannan
509 Points

"Try and Except"tutorial, stuck

this is super basic and im sure its just some syntax error or something specific to the tutorial but I cant figure out what.

its just supposed to define a function that takes two arguments, adds them, and returns the result.

I keep getting "Bummer! Try again!" which is super helpful/s.

trial.py
def add(x,y):
    x+y=z
    return z

1 Answer

Colton Ancell
Colton Ancell
1,636 Points

In Python, you have to keep the variable that you're assigning to on the left side of the = operator, and any computations on the right side. So, in your case, it's just a matter of switching x+y=z to z=x+y. Hope this clarifies things for you!

Seamus Hannan
Seamus Hannan
509 Points

thanks! it also wanted me to write it as:

def add(x,y):
    return x+y

and in the next part:

def add(x,y):
    return float(x)+float(y)

(I figured out how to format these!)