lundi 26 octobre 2015

Even or Odd? Python in JES Program

Here is my code, I am having trouble getting the last IF statement to work properly, I want it to print only when the answer is not even or odd, but it prints almost every time. how should i fix it?

def evenOdd(x):
 for x in range (1, 6):
  num= random.randrange(1,101)
  ans=raw_input("Is" + str(num) + "Odd or Even?") 
  if (num % 2 == 0 and ans=="even") or (num % 2 == 1 and ans == "odd"):
    print "correct" 
  if (num % 2 == 0 and ans=="odd") or (num % 2==1 and ans == "even"):
    print "incorrect"
  if (num % 2 ==0 or num % 2 == 1 and ans != "odd" or ans != "even"):
    print "Please answer with Even or Odd"

Aucun commentaire:

Enregistrer un commentaire