代码:
def Division():
print "************************\n""********DIVISION********\n""************************"
counter = 0
import random
x = random.randint(1,10)
y = random.randint(1,10)
answer = x/y
print "What will be the result of " + str(x) + '/' + str(y) + " ?"
print "\n"
userAnswer = input ("Enter result: ")
if userAnswer == answer:
print ("Well done!")
print "\n"
userInput = raw_input ("Do you want to continue? \n Enter 'y' for yes or 'n' for no.")
if userInput == "y":
print "\n"
Division()
else:
print "\n"
Menu()
else:
while userAnswer != answer:
counter += 1
print "Try again"
userAnswer = input ("Enter result: ")
if counter == 3: break
userInput = raw_input ("Do you want to continue? \n Enter 'y' for yes or 'n' for no.")
if userInput == "y":
print "\n"
Division()
else:
print "\n"
Menu()
在这种情况下,我希望x
价值总是大于y
价值。我该怎么做?减法代码类似,问题保持不变,目标是避免负结果。