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

Giacomo Melzi
Giacomo Melzi
3,095 Points

I really don't know what I'm doing wrong in this exercise. Please help :)

def add(pizza, pasta): float(pizza, pasta) return(pizza + pasta)

Obviously is wrong since it gives me error but I don't know why and what should be the right form.

trial.py
def add(pizza, pasta):
  float(pizza, pasta) 
    return(pizza + pasta)

4 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

Apply float to each argument individually:

def add(pizza, pasta):
    a = float(pizza)
    b = float(pasta) 
    return a + b
Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

float takes a single argument and returns a result. Also your return is indented too far and it isn't a function. It's a keyword so parens not needed:

def add(pizza, pasta):
  fpizza, fpasta = float(pizza), float(pasta) 
  return fpizza + fpasta
Gianmarco Mazzoran
Gianmarco Mazzoran
22,076 Points

Ciao Giacomo Melzi,

un metodo rapido oltre a quelli giร  postati รจ questo:

def add(pizza, pasta):
    return float(pizza) + float(pasta)