Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,732 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,167 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)