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
Post a Comment