0
number = int(input("Type your number to check even or odd :"))
    for number in range (1,100):
    if(number%2) == 0:
        print("This is even number")
    elif number > 100:
        print("Enter the valid number from 1 to  100")
    else:
        print("This is ODD number")

i am a beginner in python language , I have written code to read the number as EVEN or ODD in for loop condition between (1,100). correct me if making any mistakes in my code .

pullidea-dev
  • 1,768
  • 1
  • 7
  • 23
Ansar
  • 1

2 Answers2

0

Why are you using for loop, just check the condition like if number > 100;the number is invalid.Check this example

nos=int(input())
if(nos>100):
  print("Enter the valid number from 1 to 100 ")
else:
  if(nos % 2 ==0):
    print("Number is Even")
  else:
    print("Number is Odd")
Vibhav Surve
  • 73
  • 1
  • 6
0

There are mistakes in your code.

1.Indentation error at the 2nd line.(Remove whitespace before for loop.)

2.The name of the input variable and the iterator name in for loop is same. So your intended logic would run on the numbers from 1 ,2, 3 ..... 99. It never runs on the user entered value. So change the name of any variable. Both cant be 'number'.

3.Although you change the name of the variable, you initialised for loop with 100 iterations so you see output 100 times.

so if you want to check the numbers between given range which are even or odd you can try this..

num = int(input(" Please Enter the Maximum Number : "))

for number in range(1, num+1):
    if(number % 2 == 0):
        print("{0} is Even".format(number))
    print("{0} is Odd".format(number))
Pavan Sai
  • 127
  • 2
  • 11