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

last challenge of trial.py

Sry guys but I am stucked again, I don't understand why i'm not able to solve this problem. is it normal? after all those lessons I barely remember something :(

trial.py
def add( a, b ):
try:    
    a = float(a)
    b = float(b)
    x = a + b 
except ValueError:
    return None
else:
    return x;
add (10 , 2)

2 Answers

Hey Michele,

You're basically there!

It's always pretty difficult at the outset so don't be discouraged!

def add(a, b): #You don't necessarily need the spaces before or after your paramaters
  try:    #Python relies on indentation, so make sure everything is indented properly within the function.
      a = float(a)
      b = float(b)
      x = a + b 
  except ValueError:
      return None
  else:
      # return x;
      return x #Python doesn't need semicolons (thank goodness)
add(10 , 2) #No space needed between your function name and the parameters

I hope this helps! Let me know how it went.

Kurt

Thx Kurt, very Helpful :)

No problem! Good luck!