来自《核心编程第二版》 #!/usr/bin/env python #easyMath.py---it is a veryeasy children math game. """ """ #use add(),sub(),and random number. from operator import add,sub from random import randint,choice #operators are stored in the dict. ops = {'+':add,'-':sub} MAXTRIES = 2 def doprob(): #firstly,it must random choice an operator, #and two number to reverse. op = choice('+-') nums = [randint(1,10) for i in range(2)] nums.sort(reverse=True) #get the value of ans. ans = ops[op](*nums) pr='%d %s %d='%(nums[0],op,nums[1]) #set the time of oops is 3,and if you input 3 times #and the result is incorrect,it inputs the correct #answer. oops = 0 while True: try: if int(raw_input(pr)) &