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 trialGeorge Lugo
Python Web Development Techdegree Student 922 Pointsi don't understand why this is not working
def add("John", "Kelsey"): total = float("John" + "Kelsey") return total
def add("John", "Kelsey"):
total = float("John" + "Kelsey")
return total
2 Answers
Torsten Lundahl
2,570 PointsThe challange is asking you to add two arguments and return the total. You are defining two strings, and not two variables.
Change this:
def add("John", "Kelsey"):
total = float("John" + "Kelsey")
return total
To this:
def add(John, Kelsey):
total = float(John + Kelsey)
return total
markmneimneh
14,132 PointsHello
you cant cast string to float unless they are 'numeric' string ... note the ' '
example
total = float("1.005") + float("2.055")
should work
total = float("John") + float("Kelsey")
should not work
what you can do is
total = "John" + "Kelsey"
even better
total = "John" + " Kelsey"
or
total = "John" + " " + "Kelsey"
to have a space