Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

You're doing great! Just one more task but it's a bigger one. Right now, we turn everything into a float. That's great

i am lost and i dont know where

def add(num1, num2):
        return int (num1) + int (num2)
    except ValueError:
        return None
        return num1 + num2
        a = float(num1)
        b = float(num2)
        return a + b

2 Answers

Hi there!

Ah so close! The good news is you get the try,except,else block, I think maybe the question just threw you a bit.

Your try case will return the numbers as integers if they can be converted to ints. It actually wants you to return floats like in the last question, so rather than return in your try condition, just reassign the variables to floats, and then you can return them, added together in the else case.

Hope it helps!

Hello, I am also seem to be having trouble with the third task in this quiz, right now I have:

def add(bob, sue):
            return int(bob) + int(sue)
        except ValueError:
            return None
            return(float(bob) + float(sue))

What am I doing wrong or missing?

Please & Thank you for any help