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

Challenge 3 of 3: Try Except Else

this was my step 2: def add(pens, pencils): return(float(pens) + float(pencils))

step 3 def add(pens, pencils): return(float(pens) + float(pencils)) try: pens = input("Enter number of pens" ) pencils = input("Enter number of pencils" ) except ValueError: return(None) else: add = float(pens) + float(pencils) return(add) I'm stuck..please help

trial.py
def add(pens, pencils):
    return(float(pens) + float(pencils))
try:
    pens = input("Enter number of pens" )
    pencils = input("Enter number of pencils" )
except ValueError:
    return(None)
else:
    add = float(pens) + float(pencils)
    return(add)

1 Answer

Reyam Marcos
PLUS
Reyam Marcos
Courses Plus Student 10,367 Points

your try, except and else should be inside of your function, your first return should be inside of your try: ,

def add(one, two):
    try:
        return float(one) + float(two)
    except ValueError:
        return None
    else:
        return float(one) + float(two)

hope it helps