0
n = input("Enter your number: ")
if n%2 != 0:
    print("Weird")
elif n%2 == 0:
    if n>1 and n<6:
        print("Not weird")
    elif n>=6 and n<=20:
        print("Weird")
    elif n>20:
        print("Not Weird")

While running this code I got the error message. I could not find the reason.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • 2
    You forgot to convert `n` to a number. When applied to a string, `%` is the substitution operator, not the remainder. – DYZ Aug 01 '21 at 19:14
  • Does this answer your question? [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – wjandrea Jul 23 '22 at 21:21

2 Answers2

0

The problem is that you didn't convert your input to integer.

so instead of calculating remainder of n by 2. , You are get into string formatting in line if n%2 != 0:

The old way of formatting string was :

name = 'John'
print('hi %s' % name )
S.B
  • 13,077
  • 10
  • 22
  • 49
0

SorusH is right, you didn't convert your input to integer, you should try something like

n = int(input("Enter your number: "))

to convert the input into an integer

Oax.exe
  • 1
  • 2