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

nicholas Christie
nicholas Christie
433 Points

do know what to do here

?

trial.py
def add(always,win):
    try:
    add="always,win"
    except ValueError:
    return(None)
    first_num=float(always)
    second_num=float(win)
    else:
    return(first_num+second_num)

1 Answer

Wesley Trayer
Wesley Trayer
13,812 Points
def add(always,win):
    try:
    add="always,win"  # Remember to indent blocks of code under a "try/except", also the variable "add" is not used anywhere else in the code
    except ValueError:
    return(None)
    first_num=float(always)  # You are "trying" to turn "always" into a float. This line, and the next one should be in the try.
    second_num=float(win)
    else:
    return(first_num+second_num)

Does this help?