Can someone correct this code

Given code(is supposed to) take an integer as input (it has to be within range), and if the integer is above or equals to 90 and below or equals to 110, it will return ‘True’(string), other wise it will return ‘False’. The problem is regardless of what integer i put in, it always returns a ‘True’ string. I have a feeling i’m missing something extremely simple, but can’t seem to figure out what. Help would be much appreciated!!

``````value = input('enter value ')
a = range(0,150)

for num in a:

if num >=90:
print ('True')
break
elif num <=110:
print('True')
break
else:
print('False')
break

``````

Hello!

Are you sure the problem requires you to define a range?

The way I understand it, “it has to be within range” means it has to be between the range to fulfill the condition (>= 90 and <= 110). In this case you would need the input value and an if.

Edit

By the way, your if is not right. Read the condition carefully: above or equals to 90 and below or equals to 110

I think that structure doesn’t mean a logic “and”. It means a logic “or”, so all numbers are >= 90 or <=110. For example, num = 95, then goes into num >= 90 and print ('true). If num = 130 then goes into >= 90. If num = 35 doesn’t go into num >=90, but goes into <=110. Then, always print True.

I think, this code makes (num >= 90 OR num <=110)

I wish I have helped you

i tried it buddy. Still didn’t work:(

Try this one:
i just used the function you can write the code without using function also
You are not comparing the user input which you have stored in “value”
x

``````

value = int(input("Enter number"))

if  value >=90:
print("True")
elif value <= 110 :
print("True")
else :
print("False")

``````

Try this: Change “<=” to “>=”, “>=” to “<=” and change “True” to “False” like this

value = input('enter value ')
a = range(0,150)

for num in a:

``````if num <=90:
print ('False')
break
elif num >=110:
print('False')
break
else:
print('True')
break``````

Don’t forget to drop the equals if you are going to negate the expression!

Using OR is wrong, because whenever a number is below 110 it will be true, even if it’s not above 90. Remember that the OR operator evaluates to true if ANY of the conditions are true whereas the AND operator evaluates to true if all the conditions are true

For instance:

``````num = 50

# This evaluates to true
if (num >= 50 || num <= 60):
# hence this block executes
``````

But this would also be true:

``````num = 38

# This is also true because 38 is less than 60
if num >= 50 || num <= 60:
# This block also executes
``````