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

Maggie Wolff
Maggie Wolff
495 Points

python basics challenge task 1 of 3 try and except

how do I get this to work?

trial.py
total = def add(num1 + num2)
num1 = 427
num2 = 389
return total

3 Answers

Buddhima Sehan
Buddhima Sehan
3,820 Points

Challenge Task 1 of 3

I need you to make a new function, "add". add should take two arguments, add them together, and "return" the total.

Hello Maggie Wolff,

The Challenge as shown above have asked to make a function with two arguments passed through the function, and then those two arguments should be returned through the function itself. However in your code there are some mistake you need to correct.

total = def add(num1 + num2)

We can not assign a function to variable unless we are calling it, but in the question we are asked to create one. Moving on, we can not concatenate two variables inside the parentheses of a function which is only used to pass arguments.

num1 = 427 num2 = 389

The question did not mention any sort of assignment other than the two arguments to be created with any name we want.

return total

According to the question we can not return total as it is a variable and the question didn't mention about returning a variable but they did mention to only pass the addition of the two arguments we created for the function.

Correct answer shown below:

def add(number_one, number_two):
    return number_one+number_two
Maggie Wolff
Maggie Wolff
495 Points

I have another question..... I re-watched the video, and I checked my notes for the challenge task 2 of 3 num1 = float(num1) num2 = float(num2) def add(num1, num2): return num1+num2

Buddhima Sehan
Buddhima Sehan
3,820 Points

Can you elaborate your question please ?

Maggie Wolff
Maggie Wolff
495 Points

after i looked through anything i could look through, I went back to the challenge task, finished the first challenge, and am stranded on the second.