import random deffun1(x, y, z): s =str(x)+ 文章来源站点https://www.yii666.com/" + "+str(y)+" + "+str(z)+" = "+str(x + y + z) return s deffun2(x, y, z): s =str(x)+" + "+str(y)+" - "+str(z)+" = "+str(x + y - z) return s deffun3(x, y文章来源地址42307.html, z): s =str(x)+" - "+str(y)+" + "+str(z)+" = "+str(x - y + z) return s deffun4(x, y, z): s =str(x)+" - "+str(y)+" - "+str(z)+" = "+str(x - y - z) return s defgenerate(num): s =set() whilelen(s)< num: x = random.randint(1,99) y = random.randint(1,99) z = random.randint(1,99) if((x + y >=0and x + y <=100) and(y + z >=0and文章来源地址42307.html y + z <=100) www.yii666.com and(x + z >=0and x + z <=100) and(x + y + z >=0and x + y + z <=100)): s.add(fun1(x, y, z)) if((x + y >=0and x + y <=100) and(y - z >=0and y - z <=100) and(x - z >=0and x - z <=100) and(x + y - z >=0and x + y - z <=100)): s.add(fun2(x, y, z)) if((x - y >=0and x - y <=100) and(- y + z >=0and- y + z <=100) and(x + z >=0and x + z <=100) and(x - y + z >=0and x - y + z <=100)): s.add(fun3(x, y, z)) if((x - y >=0and x - y <=100) and(- y - z >=0and- y -www.yii666.com z <=100) and(x - z >=0and x - z <=100) and(x - y - z >=0and x - y - z <=100)): s.add(fun4(x, y, z)) return s defsave_in_file(answers, answer_file, question_file): withopen(answer_file,'a')as f: # 每次输入前清空文件 f.seek(0) f.truncate() cnt =1 for ans in answers: text =str(cnt)+") "+ ans +'\n' f.write(text) cnt +=1 withopen(question_file,'a')as f: f.seek(0) f.truncate() cnt =1 for ans in answers: ques =str(cnt)+") "+ ans[: ans.find('=')+1]+"\n" f.write(ques) cnt +=1 save_in_file(generate(1000), "C:\\Users\\sibyl\\Desktop\\calculation\\answer.txt", "C:\\Users\\sibyl\\Desktop\\calculation\\question.txt")