Welcome to the Treehouse Community
Looking to learn something new?
Is the issue with my "Try" block the number of arguments represented?
I don't see where its syntactically necessary to have multiple arguments in the input function under my try block, but I'm thinking that such maybe the issue as to why my code is incorrect. Could someone skim it for me and tell me the issue please?
def add(num1,num2): try: addition= int(input("Give me a number: ") except ValueError: return("None") else: num1=float(num1) num2=float(num2) return(num1+num2)
Haider AliPython Development Techdegree Graduate 24,724 Points
Hi there Reign, there are just a couple of things wrong with your code. Firstly, in the
try block, you should be attempting to convert the 2 arguments to floats using the
float() function. Also, return is a keyword, not a function so it does not require parenthesis after it. Furthermore,
None is not a string, so it does not require quote marks around it. Make these changes and you should be good to go!
def add(num1,num2): try: float(num1) float(num2) except ValueError: return None else: return float(num1) + float(num2)
If you have any further questions please let me know :).