0

I am new to python and this code is like ,why would it give me error. i came from java background so i am unable to understand why is this happening . i saw many answers but i cant understand what actually they are trying to say .

n=input("Enter a Number :")

if n%2==0:
    print("Even Number")
else:
    print("oddNumber")

Error I am Facing is :

    Traceback (most recent call last):
      File "Proj2.py", line 5, in <module>
        if (n%2)==0 :
    TypeError: not all arguments converted during string formatting
norok2
  • 25,683
  • 4
  • 73
  • 99
ankasaw99
  • 19
  • 4
  • Because `input` always returns a string. You need `n=int(input("Enter a Number :"))` – roganjosh Dec 26 '19 at 13:52
  • https://stackoverflow.com/questions/9792387/python-modulus-giving-string-formatting-errors – Aven Desta Dec 26 '19 at 14:00
  • Welcome to python and stackoverflow. Whenever you got problems with your code the first thing you should do is to google your errors. This will most of the time will result in finding someone else in the past having the same errors as yours. – Aven Desta Dec 26 '19 at 14:02
  • Yes , Thank you i am greatful – ankasaw99 Dec 26 '19 at 18:02

1 Answers1

1

You should convert your input to int, otherwise input() would just give you a string, e.g.:

n=input("Enter a Number :")

to become:

n = int(input("Enter a Number :"))
norok2
  • 25,683
  • 4
  • 73
  • 99