Second grade math exercises generation
As a parent not easy
. 1 #coding: UTF- . 8 2 Import Random . 3 # mathematical exercise second grade (by less than plus or minus 100) 4 # of the generated title . 5 COUNT = 50 . 6 # title per line . 7 lineNum = . 5 . 8 the while COUNT> 0 : 9 # 1 is added obtaining the symbol, to reduce 2, 3 by 10 operator = the random.randint ( 1 , 3 ) . 11 # obtain operands and the operation result 12 is STR = "" 13 is num1 num2 = result = = 0 14 IF operator == 3 : # multiplication formulas 15 num1 = random.randint(1,9) 16 num2 = random.randint(1,9) 17 result = num1*num2 18 str = "X" 19 elif operator == 2: #减法 20 num1 = random.randint(2,100) 21 num2 = random.randint(1,num1) 22 result = num1 - num2 23 str = "-" 24 else: #加法 25 num1 = random.randint(1,100) 26 num2 = random.randint(0,100-num1) 27 result = num1 + num2 28 str = "+" 29 print("%d%s%d=\t\t" %(num1,str,num2),end = "") 30 count -= 1 31 if count%5 == 0: 32 print()