zoukankan      html  css  js  c++  java
  • (双人项目)四则运算 组员:杨钰宁 闫浩楠 开发语言:Python。

    需求分析:1.适用人群:小学生。

                  2.能进行“+,—,*,/” 的四则运算。难度可以随时修改。

                  3.提交试卷后可以显示所得分数并显示错题个数。

                  4.可以显示答对的题及其打错的题的序号。

    代码如下:

    import random

    rightnum=0

    wrongnum=0

    right=[]

    wrong=[]

    for i in range(1,11):

    a=random.randint(1,9)

    b=random.randint(1,9)

    caltype=random.randint(0,3)

    if caltype == 0:

    result=a+b

    print('('+str(i)+')'+str(a)+'+'+str(b)+'=')

    inputresult=input()

    if int(inputresult) == result:

    rightnum=rightnum+1

    right.append(i)

    else:

    wrongnum=wrongnum+1

    wrong.append(i)

    if caltype == 1:

    result=a-b

    print('('+str(i)+')'+str(a)+'-'+str(b)+'=')

    inputresult=input()

    if int(inputresult) == result:

    rightnum=rightnum+1

    right.append(i)

    else:

    wrongnum=wrongnum+1

    wrong.append(i)

    if caltype == 2:

    result=a*b

    print('('+str(i)+')'+str(a)+'*'+str(b)+'=')

    inputresult=input()

    if int(inputresult) == result:

    rightnum=rightnum+1

    right.append(i)

    else:

    wrongnum=wrongnum+1

    wrong.append(i)

    if caltype == 3:

    while a%b!=0:

    a=random.randint(1,9)

    b=random.randint(1,9)

    result=round(a/b)

    print('('+str(i)+')'+str(a)+'/'+str(b)+'=')

    inputresult=input()

    if int(inputresult) == result:

    rightnum=rightnum+1

    right.append(i)

    else:

    wrongnum=wrongnum+1

    wrong.append(i)

    print('The score is:'+str(rightnum*10))

    print('wrongnumber:'+str(wrongnum))

    print('The right answer number:'+str(right))

    print('The wrong answer number:'+str(wrong))

    开发心得:本程序独立完成,疑点通过上网查询精心解决。Python里有许多已经封装好的BIF函数,可以直接进行调用。如代码中生成随机数的random.randint。这些内置函数还需多多积累。经过多次试验及网上调查后才得知Python中四则运算符调用后无法行使对应的功能,所以使用语句caltype=random.randint(0,3)随机生成0,1,2,3四个数,每个数字对应一个运算法则,实现四则运算的功能。通过两次程序的编写,对Python语言有了一定的认识。

  • 相关阅读:
    phpquery中文手册
    Fiddler工具使用介绍一
    Xshell出现要继续使用此程序必须应用到最新的更新或使用新版本
    PHP Ajax 跨域问题最佳解决方案
    charles和Fiddler感觉哪个更好用
    趣味小应用:用HTML5消磨时光 狼人:
    开发人员必知的20+HTML5技巧 狼人:
    云计算时代:LAMP何去何从? 狼人:
    Adobe改善Flash隐私功能 狼人:
    LAMP网站架构方案分析 狼人:
  • 原文地址:https://www.cnblogs.com/yangyuning/p/5845869.html
Copyright © 2011-2022 走看看