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

Joseph Duarte
Joseph Duarte
468 Points

I can't seem to pass challenge task 3 of 3:

def add(n1,n2): try: return float(n1) + float (n2) except ValueError: return ("None") else: return float(n1) + float (n2)

Thx

trial.py
def add(n1,n2):
try:
  return float(n1) + float (n2)
except ValueError:
  return ("None")
else:
  return float(n1) + float (n2)

1 Answer

Gavin Ralston
Gavin Ralston
28,770 Points

You don't need quotes around None

In fact, you don't need the else statement in this case, either, although that'll work just fine anyway. You'll either return None or the sum of the input values.

Joseph Duarte
Joseph Duarte
468 Points

Thank you Gavin

In addition to your answer the other issue was the indentation in the try block. I did not have the whole try block indented.

Joseph Duarte
Joseph Duarte
468 Points

Thank you Gavin

In addition to your answer the other issue was the indentation in the try block. I did not have the whole try block indented.

Gavin Ralston
Gavin Ralston
28,770 Points

Ah yeah, I saw the indentation but thought maybe that was a cut-and-paste problem. Good to see you caught that :)