zoukankan      html  css  js  c++  java
  • 作业要求 20180925-6 四则运算试题生成

    本次作业要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2148

    git地址https://git.coding.net/fanhongda/test.git

    要求1 参考《构建之法》第4章两人合作,结对编程上述功能,要求每人发布随笔1篇 (代码是共同完成的,博客是分别完成的)。 (1) 给出每个功能的重点、难点、编程收获。(2)给出结对编程的体会,以及 (3) 至少5项在编码、争论、复审等活动中花费时间较长,给你较大收获的事件。 (10分)

    本次作业在阅读《构建之法》时曾见过举例,并且书中作业也和这个类似,当时进行了一定的了解,但是本次作业所有的功能中都因为对语法的不熟悉造成了一些困难。

    功能1 要随机生成数字、运算符号

    功能2 要判断括号的生成条件,注意加减和乘除运算之间的优先级

    功能3 要避免题目出现重复,并且要求打印出来的效果精美,不要造成题目混乱之感

    功能4 实现分数运算要使用fraction(这个功能不会,所用函数也不熟悉,由同伴指导)

    生成题目算式:

    while(i <= 20):
        list=[]
        ls_2=[]
        list.append(createnum())
        list.append(createOperator())
        list.append(createnum())
        list.append(createOperator())
        list.append(createnum())
        list.append(createOperator())
        list.append(createnum())
    
        ls_2 = string(list)
        list_str = ''.join(ls_2)
        print(list_str)
        answer = eval(list_str)
        answer_input = float(input('?'))
        if answer_input == answer:
            print("答对啦")
            t = t+1
        elif answer != answer_input:
            print("答错了,答案是" + str(answer) +"")
        #list.clear()
        i=i+1
    print("你答对了" + str(t) + "道,共20道")

    括号的支持

    def getk(list):
        str1 = [0,2,4]
        str2 = [3,5,7]
        start = random.choice(str1)
        if start == 4:
            list.append(')')
            list.insert(start, '(')
        if start == 0:
            end = random.choice(str2)
            if end == 7:
                list.append(')')
            else:
                list.insert(end,')')
            list.insert(start, '(')
        elif start == 2:
            end = random.choice(str2)
            if end == 7:
                list.append(')')
            else :
                list.insert(end, ')')
            list.insert(start, '(')

    输出题目

    if sys.argv[1] == '-c':
        if int(sys.argv[2]) < 0:
            print("题目数量必须是正整数")
        elif sys.argv[2] != sys.argv[2]:
            print("题目数量必须是正整数")
        else:
            n = int(sys.argv[2])

    输出文件

    temp=sys.stdout # 记录当前输出指向,默认是consle
        with open("outputlog.txt","a+") as f:
         sys.stdout=f # 输出指向txt文件
         print(list_str1)
         sys.stdout=temp # 输出重定向回consle
         print(f.readlines()) # 将记录在文件中的结果输出到屏幕

    支持分数

    def reduction(self,num):
                a = num.numerator
                b = num.denominator
                divisor = function1().getMaxDivisor(a, b)
                a = a / divisor
                b = b / divisor
                num.setNumerator(a)
                num.setDenominator(b)
                return num
    
    
            def getMaxDivisor(self,numerator,denominator) :
                if denominator == 0:
                    return numerator
                else:
                    x = numerator%denominator
                    return function1().getMaxDivisor(denominator, x)

    (2)结对编程的感触

    1、最大的感触是我和同伴赵美增的编程水平都不高,而且初次之外我的基础薄弱,导致进度缓慢

    2、结对过程中有时会忘记自己的角色,指导者看到编程者出现错误总是会想自己上手

    3、编程过程中难免出现分歧、但是讨论不仅仅为了解决问题而且得到了学习

    4、结对编程是一个互相监督和学习的国过程,在此过程中容易发现个人编程中出现的问题并予以纠正,总体而言,这是一个做中学的过程,对能力提高有一定帮助

    要求2要求2 给出照片1张,包括结对的2位同学、工作地点、计算机,可选项包括其他能表达结对编程工作经历的物品或场景。

  • 相关阅读:
    Python运行时遇到UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)的问题
    Android 网络通信架构学习
    将Windows MyEclipse的web项目移植到Debian下
    build-essential : Depends: libc6-dev but it is not going to be installed or libc-dev 解决办法
    Debian可用的源 —— 23% waiting for headers解决办法
    将访问服务器的工作交由Service承担
    Servlet回传的数据显示在界面上
    Android客户端和Servlet服务器端通过JSON交互
    Welcome to My Blog!
    【三木夜话】无穷级的恐惧
  • 原文地址:https://www.cnblogs.com/fanhongda/p/9756788.html
Copyright © 2011-2022 走看看