NameError is not coming due to this function. Also, your function is written wrongly. NameError will not be solved(because that part you didn't share). But other error which comes to you by addtwo function will be solved by this:-
>>> def addtwo(a,b):
... if isinstance(a, int) and isinstance(b,int):
... added = a+b
... else:
... added = "Insert a number!"
... return added
>>> print(addtwo(7,5))
12
>>> print(addtwo("str",5))
Insert a number!
In your code if int(a) and int(b):
is creating problem while checking for integer value. It will give this error ValueError: invalid literal for int() with base 10: 'str'
. So use isinstance
instead of int
. And also added=print("Insert a number!")
is completely wrong.