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 trialSachin Kanchan
564 PointsUnable to do the ADD argument function program
I am unable to complete the first challenge after THE EXCEPTION TO THE RULE video tutorial. Please help
def add():
guess1 = int(input('Choose Entry 1: '))
guess2 = int(input('Choose Entry 2: '))
total = (guess1+guess2)
print(total)
break
add()
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! First, challenges tend to be very literal and you should try not to do anything the challenge doesn't specifically ask for. In this case, it's asking you to define a function that takes two arguments (or has two parameters). These are going to be numbers sent into the function by Treehouse. You are using two input
statements to get two numbers, but those should have been sent in by whatever is calling the function. Also, you declared a new variable named total
which wasn't asked for and you're printing out the value. But the challenge asks you to return
the value. You should also not be calling the function yourself. It will be called by Treehouse where they will send two numbers of their choosing. Here was my solution for Step 1.
def add(x, y): #this function accepts two arguments
return x + y #return the sum of the two numbers sent in
Hope this helps!
Sachin Kanchan
564 PointsSachin Kanchan
564 PointsHoly beard of Odin. I know just how easy these code challenges are. But every single time I just overthink and overestimate the difficulty, I feel like - they definitely don't just mean this. There's gotta be more. Thanks
I'll post below, what I cooked up for this coding challenge, while waiting for answers.
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherSachin Kanchan I've done a lot of courses here at Treehouse and a lot of code challenges. From my experience, if you think you're overcomplicating the challenge, chances are that you're correct The best "hints" (so to speak) are the instructions. Granted, the challenges get trickier as the difficulty increases, but I still feel like this is pretty solid advice.
Sachin Kanchan
564 PointsSachin Kanchan
564 PointsI'm trying to ensure that the user only inputs both strings or both integers.
If commas, decimals or symbols are used, it'll throw a EXCEPT ValueError. But I'm unable to incorporate the EXCEPTION in the code. Please guide :) Jennifer Nordell
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherIs this second set of code for the challenge or for your own personal thing you're working on?
Sachin Kanchan
564 PointsSachin Kanchan
564 PointsJennifer Nordell For Own practice
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherA
ValueError
exception is a built in exception type in Python. It will be invoked when a function receives an argument of the correct type but an inappropriate value. The only function you have now in your code that can produce aValueError
is the place where you are attempting to convert the strings to integers.You can view the documentation here.
Also, your code is missing any
try
.