1

I'm new to python. I want to design a program to get an input from user and display whether that number is even or odd. But I want to do it 3 functions. 1st function is for getting the user's input, 2nd function is to validate the number and the 3rd function is to display the result. Here is the code that I wrote:

def inputData():
    number=int(input('Enter No.'))
    return number
inputData()

def evenNo(number):
    if number%2==0:
        return True
    else:
        return False
evenNo(number)

def output(number):
    if evenNo()== True:
        print('\t Even')
    else:
        print('\t Odd')
    return number
output(number) 

It gives the following Error:

Traceback (most recent call last):
  File "C:/Users/DELL/Desktop/PPAS/Edited/TEST FINAL.py", line 11, in <module>
    evenNo(number)
NameError: name 'number' is not defined
  • 3
    This was incorrectly closed. The linked question is not the reason OP has a problem with his code – bendl Aug 17 '17 at 17:38
  • yeah -_- I don't know why he has duplicated my question -_- – Arunoda Gunawardana Adee Aug 17 '17 at 17:39
  • 3
    In case it doesn't get reopened, the problem is that you're not storing the result of `inputData()`... You should replace line 4 with `number = `inputData()` The same goes for `evenNo(number)`... – bendl Aug 17 '17 at 17:40
  • 1
    The answer is incorrectly closed. I have a solution to your question. If you could ask another question, I could answer it – Larry Aug 17 '17 at 17:42
  • @Larry should I post the same question again? – Arunoda Gunawardana Adee Aug 17 '17 at 17:44
  • @ArunodaGunawardanaAdee no. Your question *is a duplicate*. Check out the duplicate target. It explains your error in detail. – juanpa.arrivillaga Aug 17 '17 at 17:44
  • @ArunodaGunawardanaAdee Yes, I'll answer it :D (Word the question a bit differently, just so that nobody closes it too soon) – Larry Aug 17 '17 at 17:46
  • @Larry **don't**. This question is a duplicate. – juanpa.arrivillaga Aug 17 '17 at 17:46
  • [Python Scopes and Namespaces](https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces) - You may need to read that more than once and come back to it every now and then. Also [Naming and Binding](https://docs.python.org/3/reference/executionmodel.html#naming-and-binding) – wwii Aug 17 '17 at 17:47
  • The new linked post is correct, this is in fact a duplicate of that question. – bendl Aug 17 '17 at 17:48

0 Answers0