"Mobile App Design for iOS" was retired on February 24, 2020.

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

Help with Try & Except challenge Task 3 of 3

I am not understanding what I am doing wrong here. I thought I added the try block where the question instructed me and correctly structured the loop. Any insight would be greatly appreciated

trial.py
def add(num1, num2):
try: 
    return float(num1) + float(num2)
except ValueError:
    return(None)
else:
    return float(num1) + float(num2)

2 Answers

just indent your code

def add(num1, num2):
    # cod 

I just figured out that was the error. Was driving me nuts. Thank you for the response

There are two things.

  1. Your indents need correcting
  2. There is no need for the else statement, as there is no if statement.
def add(num1, num2):
    try: 
        return float(num1) + float(num2)
    except ValueError:
        return(None)

Thank you. I literally just figured out it was and indentation error. I appreciate you taking the time