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

Michael Allocco
Michael Allocco
616 Points

Am I supposed to request user input?

I'm a little unclear on what I'm being asked to provide. Am I supposed to change my code to try my code in its entirety? And, if so, am I supposed to alter it to ask for user input?

trial.py
def add(num1, num2): 
    try:
    return float(num1) + float(num2)
    except ValueError: 
        return None
    else:
        return float(num1) + float(num2)

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

no user input. Try to cast as floats; you can reassign the floated parameters to themselves or assign to new variables. Except like you are, that's fine. Return the sum of the variables, either the reassigned floats or the new variables. so your code is acceptable, you just need to indent the body of your try block so it's at the same level as the bodies of the except and else blocks.