Task for invalid number in Python

Question:

I need to write a program where numbers 100 to 200 and 0 are declared as valid. Everything else is invalid. When you put a invalid number in, it should print invalid but if the number is valid the nothing should print nothing in the terminal.

I wrote something but then when i give 155 as input it still says that it’s invalid when it shouldn’t print anything. Any ideas how I can fix it?

number = int(input())

if number < 100 or number > 200 or number != 0:
    print('invalid')
else:
    print()
Asked By: diananas

||

Answers:

You need to change number==0 instead of number!=0

number = int(input())

if number == 0 or (number > 100 and number < 200):
    print()
else:
    print('invalid')
Answered By: NIKUNJ PATEL

You probably meant :

number = int(input())

if number < 100 or number > 200 or number == 0:
    print('invalid')
else:
    print()
Answered By: Patrick

try

if number == 0 or (100 < number and number < 200):
    #valid
else:
    print("invalid")
Answered By: 6plosive
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.