-2
while True:
    ans = input('Enter a number : ')
    if ans.isalpha():
        if ans == 'q':
            break
    elif ans.isnumeric():
        if ans == 1 or ans == 0:
            print('NOT even NOR odd number')
        elif ans % 2 == 0:
            print('EVEN number')
        else:
            print('ODD number')

and goes error like this:

Traceback (most recent call last):
  File "C:/Users/Me.Qa/Desktop/app0001.py", line 9, in <module>
    elif ans % 2 == 0:
TypeError: not all arguments converted during string formatting
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
japy
  • 13
  • 1

2 Answers2

0

You din't convert "ans" variable to int. Just add

ans = int(ans)

before

if ans == 1 or ans == 0:
Val
  • 39
  • 7
0

ans is a String. You can't do math on a String; you need to parse it as a number first.

As noted in the comments, change you second part to:

elif ans.isnumeric():
    # int takes a string and returns 
    #  the number it represents
    num_ans = int(ans) 
    if num_ans == 1 or num_ans == 0:
        print('NOT even NOR odd number')
    elif num_ans % 2 == 0:
        print('EVEN number')
    else:
        print('ODD number')
Carcigenicate
  • 43,494
  • 9
  • 68
  • 117