math - Problems with Python comparion if statement -


here's code:

import random  in range(10):      x=random.randint(1, 10)     y=random.randint(1, 10)      prompt="what " + str(x) +" times " + str(y) + "? "     answer = raw_input(prompt)      z = x * y       if answer == x*y:         print "that's right"     else:         if answer == x*y:             print "that's wrong"             print answer             print z 

what's wrong it, doesnt give true statements

raw_input returns string, x , y int. compare string , int.

you may cast answer in int:

answer_int = int(answer) 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -