zoukankan      html  css  js  c++  java
  • 四则运算

    1.代码

    import random
    def t():
        sym = ['+', '-', '×', '÷']
        f= random.randint(0, 3)
        n1 = random.randint(1, 20)
        n2 = random.randint(1, 20)
        result = 0
        if f== 0:
            result  = n1 + n2
        elif f == 1:
            n1, n2 = max(n1, n2), min(n1, n2)
            result  = n1 - n2
        elif f== 2:
            result  = n1 * n2
        elif f == 3:
            n1, n2 = max(n1, n2), min(n1, n2)
            while n1 % n2 != 0:
                n1 = random.randint(1, 10)
                n2 = random.randint(1, 10)
                n1, n2 = max(n1, n2), min(n1, n2)
            result  = int(n1 / n2)
        print(n1, sym[f], n2, '= ', end='')
        return result
    def test():

        print('输入所需要的题目数量')
        n=int(input())
        result =[]
        m=0
        while m<=(n-1):
            print(m+1,end='、')
            result .append(t())
            print(' ')
            m=m+1
        m=0
        print('对应的答案:')
        while m<=(n-1):
            print(m+1,'、',result [m])
            m=m+1
    print('选择想要的模式')
    print('1、进行四则运算')
    print('2、制作题库')
    n=int(input())
    if n==1:
        while True:
            result  = t()
            j= input()
            s= int(j)
            if s== result :
                print('right')
            else:
                print('error.,the answer is', result )
    if n==2:
        test()

    2.运算结果

  • 相关阅读:
    idea语法检查红线隐藏配置
    spring security
    linux centos7下安装fastdfs
    定时任务在多个服务实例之间最多只执行一次
    C++11:01auto关键字
    chap3 数组 #C
    django之模型层 各种查询 数据库查询优化相关 事务使用
    django orm 中表与表之间建关系 视图层 路由层 django请求生命周期
    django 静态文件的配置 orm 中 字段与数据的增删改查 使用MySQL数据库
    BOM,DOM, JS,JQ
  • 原文地址:https://www.cnblogs.com/shwan-1949/p/14057207.html
Copyright © 2011-2022 走看看