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

Rehan Hussain
PLUS
Rehan Hussain
Courses Plus Student 2,199 Points

Confused with the float!

This is not running for me!

trial.py
def add(num1, num2): 
    float(num1,num2) 
    return(num1 + num2) 
add(5,6) 

5 Answers

Line 2 is your issue you cannot put 2 arguments to float() - just one at a time

Rehan Hussain
PLUS
Rehan Hussain
Courses Plus Student 2,199 Points

What would be the correct way of writing this

float(num1) float(num2)

?

hi there, you could do the following

def add(num1, num2): 
    float(num1)
    float(num2)
    return(num1 + num2) 
add(5,6) 

or to use less lines

def add(num1, num2): 
    return(float(num1) + float(num2)) 
add(5,6) 
Rehan Hussain
PLUS
Rehan Hussain
Courses Plus Student 2,199 Points

Hey guys,

Task 3 just won't run looking for some help!

def add(x,y): try: a = float(x) b = float(y) except ValueError return None else return(a+b)

Have you missed a colon after ValueError?