import random
from random import choice ops = ('+','-','×','÷')
ans = []
i=0
while i < 100 :
op1 = choice(ops)
op2 = choice(ops)
n = random.randint(1,9)
if op1 == '+' and op2 == '+' :
a = random.randint(0,100)
b = random.randint(0,100-a)
c = random.randint(0,100-a-b)
ans.append(a + b + c)
elif op1 == '+' and op2 == '-' :
a = random.randint(0,100)
b = random.randint(0,100-a)
c = random.randint(0,a+b)
ans.append(a + b - c)
elif op1 == '+' and op2 == '×' :
b = random.randint(0,9)
c = random.randint(0,9)
a = random.randint(0, 100 - b * c)
ans.append(a + b * c)
elif op1 == '+' and op2 == '÷':
c = random.randint(1, 9)
b = n * c
a = random.randint(0, 100 - b / c)
ans.append(a + b / c)
elif op1 == '-' and op2 == '+' :
a = random.randint(0,100)
b = random.randint(0,a)
c = random.randint(0,100-a+b)
ans.append(a - b + c)
elif op1 == '-' and op2 == '-' :
a = random.randint(0,100)
b = random.randint(0,a)
c = random.randint(0,a-b)
ans.append(a - b - c)
elif op1 == '-' and op2 == '×' :
b = random.randint(0,9)
c = random.randint(0,9)
a = random.randint(b*c,100)
ans.append(a - b * c)
elif op1 == '-' and op2 == '÷':
c = random.randint(1, 9)
b = n * c
a = random.randint(100 - b / c,100)
ans.append(a - b / c)
elif op1 == '×' and op2 == '+' :
a = random.randint(0, 9)
b = random.randint(0, 9)
c = random.randint(0,100-a*b)
ans..append(a * b + c)
elif op1 == '×' and op2 == '-' :
a = random.randint(0,9)
b = random.randint(0,9)
c = random.randint(0,a*b)
ans.append(a * b - c)
elif op1 == '÷' and op2 == '+' :
b = random.randint(1, 9)
a = n * b
c = random.randint(0,100 - a / b)
ans.append(a / b + c)
elif op1 == '÷' and op2 == '-' :
b = random.randint(1,9)
a = n * b
c = random.randint(0,a / b)
ans.append(a / b - c)
else :
continue
print("第%s题: %s%s%s%s%s=" % (i + 1, a, op1, b, op2, c))
i += 1
print("*"*60)
i = 0
while i < len(ans):
print("第%s题的答案是:%d"%(i+1,ans[i]))
i += 1

  

Python自动生成100以内加减乘除混合运算题的更多相关文章

  1. 利用python自动生成verilog模块例化模板

    一.前言 初入职场,一直忙着熟悉工作,就没什么时间更新博客.今天受“利奇马”的影响,只好宅在家中,写写技术文章.芯片设计规模日益庞大,编写脚本成了芯片开发人员必要的软技能.模块端口动不动就几十上百个, ...

  2. 从用python自动生成.h的头文件集合和类声明集合到用python读写文件

    最近在用python自动生成c++的类.因为这些类会根据需求不同产生不同的类,所以需要用python自动生成.由于会产生大量的类,而且这些类是变化的.所以如果是在某个.h中要用include来加载这些 ...

  3. JS练习--自动生成100个li

    点击按钮,自动生成100个li,红.黄.蓝.绿四种颜色的顺序显示出现在页面中 CSS: ;;} ul,li{list-style: none;} #ul1{position: relative;} # ...

  4. Python自动生成代码工具

    项目中有一个需求,对一个基类而言,拥有一个比较方法和拷贝方法,某些地方需要频繁地对这两个方法进行调用.对于所有子类而言,需要重写这两个方法,并在其中维护类内一些成员变量.例如有一个变量m_iMyVal ...

  5. 使用python自动生成docker nginx反向代理配置

    由于在测试环境上用docker部署了多个应用,而且他们的端口有的相同,有的又不相同,数量也比较多,在使用jenkins发版本的时候,不好配置,于是想要写一个脚本,能在docker 容器创建.停止的时候 ...

  6. 利用Python自动生成暴力破解的字典

    Python是一款非常强大的语言.用于测试时它非常有效,因此Python越来越受到欢迎. 因此,在此次教程中我将聊一聊如何在Python中生成字典,并将它用于任何你想要的用途. 前提要求 1,Pyth ...

  7. python 自动生成C++代码 (代码生成器)

    python 代码自动生成的方法 (代码生成器) 遇到的问题 工作中遇到这么一个事,需要写很多C++的底层数据库类,但这些类大同小异,无非是增删改查,如果人工来写代码,既费力又容易出错:而借用pyth ...

  8. python自动生成bean类

    近期在学习python,一直在和java做对比,目前没有发现有通过字段自动生成getter setter方法,故此自己写了一个类,可以通过__init__方法传入类名和字段数组,再调用内部的方法,就可 ...

  9. python 自动生成model 文件 案例分析

    生成方式 Python中想要自动生成 model文件可以通过 sqlacodegen这个命令来生成对应的model文件 sqlacodegen 你可以通过pip去安装: pip install sql ...

随机推荐

  1. [护网杯2018] easy_laravel

    前言 题目环境 buuoj 上的复现,和原版的题目不是完全一样.原题使用的是 nginx + mysql 而 buuoj 上的是 apache + sqlite composer 这是在 PHP5.3 ...

  2. Java中Date时间类

    Date:表示特定的瞬间,精确到毫秒. 构造方法: Date():根据当前的默认毫秒值创建日期对象 Date(long date):根据给定的毫秒值创建日期对象 public static void ...

  3. pytorch seq2seq闲聊机器人beam search返回结果

    decoder.py """ 实现解码器 """ import heapq import torch.nn as nn import con ...

  4. pytorch torchversion标准化数据

     新旧标准差的关系

  5. search(7)- elastic4s-search-filter模式

    现在我们可以开始探讨ES的核心环节:搜索search了.search又分filter,query两种模式.filter模式即筛选模式:将符合筛选条件的记录作为结果找出来.query模式则分两个步骤:先 ...

  6. c++动态数组的使用

    在c++中,有的时候会遇到变长的数组(不管是一维的还是二维的),这个时候就需要用到动态数组了,并且要用new和delete两个操作符,这俩操作符一般成对使用. 先说一维的动态数组吧,直接上代码 #in ...

  7. influxdb 安装

    influxdb是一款开源的时序数据库,可以用作监控系统的数据存储或用来存储基于时序进行分析的业务系统的数据存储. influxdb的部署及使用均比较简单,但是集群(官方版集群已闭源)及高可用方案较少 ...

  8. 我做了一个 HTML 可视化编辑工具,有前途吗?

    疫情在家的这段时间,我做了一个 HTML 可视化编辑工具,做的时候信心满满,差不多完成了,现在反而不如以前信心足了,这玩意有用吗?代码地址: https://github.com/vularsoft/ ...

  9. 手把手教你用Rancher创建产品质量数据库设置

    目标:在本文中,我们将介绍如何运行一个分布式产品质量数据库设置,它由Rancher进行管理,并且保证持久性.为了部署有状态的分布式Cassandra数据库,我们将使用Stateful Sets (有状 ...

  10. CF--思维练习--CodeForces - 220C Little Elephant and Shifts (STL模拟)

    ACM思维题训练集合 The Little Elephant has two permutations a and b of length n, consisting of numbers from ...