n = 24
if n % 2 == 0 (n >= 6 and n <= 20):
print("Weird")
...emits the error message:
TypeError: 'int' object is not callable
What does this mean? How can it be avoided?
n = 24
if n % 2 == 0 (n >= 6 and n <= 20):
print("Weird")
...emits the error message:
TypeError: 'int' object is not callable
What does this mean? How can it be avoided?
You need the and
or or
operator to combine the modulus condition and the range condition.
Python also allows you to use chained comparisons to test if a number is in a range.
if n % 2 == 0 or 6 <= n <= 20:
you are equating the division to 0 and the other condition all together.
you have to separate the steps, equal to zero and then check.
n = 24
if n % 2 == 0: print ("Not Weird") else: print ("Weird")
if n % 2 == 0 & (n >= 6 and n <= 20): print("Weird")
if n % 2 == 0 & (n <= 2 and n >= 5): print("Not Weird")
if n % 2 == 0 & (n > 20): print("Not Weird")