-1

I need to write a program that asks if a random number is even or odd, the user inputs the answer and then the program tells you if it is correct or incorrect. I do not know what to put in ans=raw_input("is" [random number] "Odd or Even?")

this is what i have implemented right now, what do i do to fix it?

def evenOdd():
  num=random.randrange(1,101)
  ans=raw_input("is"+num+"even or odd?")
  if ans % 2 == 0:
    print "correct"
  elif ans % 2 == 1:
    print "incorrect"
Swastik Padhi
  • 1,849
  • 15
  • 27
Lauren
  • 33
  • 4
  • 1
    Welcome to StackOverflow! You'll find that you're much more likely to receive meaningful, helpful responses if you show us code that you've written and are having trouble with, along with any error messages you've encountered. – g.d.d.c Oct 23 '15 at 20:07
  • Now that you've shown us the code, is there a particular problem you're encountering? It looks like maybe you've progressed from "I do not know what to put in..." to a different problem now (since it appears you've found [random.randrange](https://docs.python.org/3.5/library/random.html#random.randrange))? – Jeff B Oct 23 '15 at 20:23

2 Answers2

1

Take a look at python's random module. You probably want something like random.randint(1,100).

clwainwright
  • 1,624
  • 17
  • 21
1

This should solve your problem-

def evenOdd():
    num = random.randrange(1,101)
    ans = raw_input("Is "+str(num)+" even or odd?")
    if (num % 2 == 0 and ans == "even") or (num % 2 != 0 and ans == "odd"):
        print "Correct answer"
    else:
        print "Incorrect answer"
Swastik Padhi
  • 1,849
  • 15
  • 27
  • that worked great thanks! only thing now is that i need it to ask the question about 5 times in a row with a different number each time – Lauren Oct 25 '15 at 23:29
  • yes i have tried that, however i am not sure what line to the loop on and how to specify the amount, i have tried but all it did was print "correct" repeatedly – Lauren Oct 26 '15 at 13:49
  • A simple google search would get you this- `for x in range(0, 4):` to run the loop 5 times. I see that you are not actually trying anything. SO is not a code-writing service. Please learn python first. – Swastik Padhi Oct 26 '15 at 14:00