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

    以我的能力最多做到这里了= =
    总结一下问题所在
    1.不懂怎么将结果输出到.txt中,问了课代表,了解到open函数以'w'形式写入的用法,但是还是不会= =
    2.不懂检查答案......
    代码如下:
    import random

    def ac():

    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():

    sym = ['+', '-', '×', '÷']
    
    print('输入所需要的题目数量')
    
    n=int(input())
    
    result =[]
    
    m=0
    
    while m<=(n-1):
    
        print(m+1,end=' ')
    
        result .append(ac())
    
        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  = ac()
    
        j= input()
    
        s= int(j)
    
        if s== result :
    
            print('right')
    
        else:
    
            print('error.,the answer is', result )
    

    if n==2:

     test()
  • 相关阅读:
    bzoj1297 [SCOI2009]迷路
    bzoj1085 [SCOI2005]骑士精神
    bzoj1009 [HNOI2008]GT考试
    uoj#73 【WC2015】未来程序
    bzoj1016 [JSOI2008]最小生成树计数
    bzoj2818 Gcd
    python递归——汉诺塔
    python参数
    python函数
    为什么会出现__pycache__文件夹?
  • 原文地址:https://www.cnblogs.com/acacacaac/p/14055655.html
Copyright © 2011-2022 走看看