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
价值更大。我该怎么做? 减法的代码是相似的,问题保持不变,目标是避免 的负面结果。
没有你的问题不对,但对于将来的问题,考虑在遇到小问题时,不要让代码阅读。这很容易可能是“给定两个数字,你如何让x =小一个,y =大一个?” – 2012-04-22 00:53:27