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

how to check for ValueError for 2 arguments in the block code for try:

i am having trouble in the last task for the challenge where you have to check for valueError in the input values for the arguments.

trial.py
def add(num1, num2):
    try:
        num1= int(input("Give us a numbers: "))

    except ValueError:
        return None

    else:
        return float(num1) 

2 Answers

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Nagamani,

In your try block you are asking the user to supply a string. But you don't want any input from the user, you already have the inputs as the arguments to your function: num1 and num2.

Thank you. I eliminated the input from the user and it worked.