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

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

trial.py
def add(num1, num2):
    try:
        return int (num1) + int (num2)
    except ValueError:
        return None
    else:
        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):
        try:
            return int(bob) + int(sue)
        except ValueError:
            return None
        else:
            return(float(bob) + float(sue))

What am I doing wrong or missing?

Please & Thank you for any help