github项目地址: https://github.com/kongkalong/python

PSP

预估耗时(分钟)

Planning

.Estimate

48*60

Development

.Analysis

30

.Design Spec

30

.Design Review

0

.Coding Standard

30

.Design

60

.Coding

24*60

.Code Reviw

30

.Test

60

Reporting

.Test Report

0

.Size Measurement

0

.Postmortem & Process Improvement Plan

0

合计

4560

设计实现:函数zhengshu(),fenshu(),xiaoshu()分别随机生成整数,分数(包括真分数)和小数,函数sizeyunsuan()构造四则运算算式的格式为“["数值A","运算符","数值B"]”,函数transform()将数值类型的代表符号转换为实例的数值,如0->整数,函数printresult()将四则运算算式格式输出为“数值A 运算符 数值B”。

代码:

 

import random;

 

import profile;

   
 

#随机生成100以内的小数(小数点后最多两位)

 

def xiaoshu():

 

num=random.randint(0,99)+random.randint(1,99)/100;

 

string=str(num);

 

list=[];

 

list.append(num);

 

list.append(string);

 

return list;

 
 

#随机生成100以内的整数

 

def zhengshu():

 

num=random.randint(0,100);

 

string=str(num);

 

list=[];

 

list.append(num);

 

list.append(string);

 

return list;

   
 

#随机生成100以内的分数(包括真分数)

 

def fenshu():

 

while True:

 

n=random.randint(1,199);

 

m=random.randint(2,199);

 

if n!=m and n%m!=0:

 

break;

 

num=n/m;

 

string=str(n)+"/"+str(m);

 

list=[];

 

list.append(num);

 

list.append(string);

 

return list;

   
 

#将0,1,2转换为真实的整数,分数和小数

 

def transform(num):

 

if num==0:

 

return zhengshu();

 

if num==1:

 

return fenshu();

 

if num==2:

 

return xiaoshu();

   
   
 

#构造四则运算算式

 

def sizeyunsuan():

 

#四则运算算式的格式用长度为3的列表表示,如1+2相当于["1","+","2"]

 

#数值的类型表示为:0-整数,1-分数,2-小数

 

#运算符的类型表示为:0-加法,1-减法,2-乘法,3-除法

 

list=[0,0,0];    #列表初始化为0

 

list[0]=random.randint(0,2);

 

list[1]=random.randint(0,3);

 

list[2]=random.randint(0,2);

 

return list;

 
 

#输出四则运算算式

 

def printresult(listname):

 

if listname[1]==0:

 

n=transform(listname[0]);

 

m=transform(listname[1]);

 

print(n[1]+"+"+m[1]);

 

if listname[1]==1:

 

n=transform(listname[0]);

 

m=transform(listname[2]);

 

#避免出现算式的结果为负数

 

if n[0]<m[0]:

 

print(m[1]+"-"+n[1]);

 

else:

 

print(n[1]+"-"+m[1]);

 

if listname[1]==2:

 

while True:

 

n=transform(listname[0]);

 

m=transform(listname[2]);

 

#避免出现0×0

 

if m[0]!=0 or n[0]!=0:

 

break;

 

print(n[1]+"×"+m[1]);

 

if listname[1]==3:

 

n=transform(listname[0]);

 

while True:

 

#避免除数为0

 

m=transform(listname[2]);

 

if m[0]!=0:

 

break;

 

print(n[1]+"÷"+m[1]);

 
 

#利用profile性能测试工具进行效能分析

 

def fun():

 

for i in range(100000):

 

a=i*i

 
 

count=0;

 

while count<300:

 

list=sizeyunsuan();

 

printresult(list);

 

count+=1;

 

#进行效能分析

 

profile.run("fun()");

测试:

PSP

实际耗时(分钟)

Planning

.Estimate

24*60

Development

.Analysis

10

.Design Spec

15

.Design Review

0

.Coding Standard

15

.Design

20

.Coding

2*60

.Code Reviw

10

.Test

30

Reporting

.Test Report

0

.Size Measurement

0

.Postmortem & Process Improvement Plan

0

合计

1660

python四则运算2.0的更多相关文章

  1. Python 3.6.0的sqlite3模块无法执行VACUUM语句

    Python 3.6.0的sqlite3模块存在一个bug(见issue 29003),无法执行VACUUM语句. 一执行就出现异常: Traceback (most recent call last ...

  2. 结对子作业 四则运算 V2.0

    import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import ja ...

  3. Apache Qpid Python 1.35.0 发布

    Apache Qpid Python 1.35.0 发布了,Apache Qpid (Open Source AMQP Messaging) 是一个跨平台的企业通讯解决方案,实现了高级消息队列协议.提 ...

  4. python 3.4.0 简单的print &#39;hello world&#39;,出错--SyntaxError: invalid syntax

    问题描写叙述: win7下安装的python 3.4.0版本号, 在命令行里写入简单的输出语句: print 'hello world' 然后enter,结果返回结果为: SyntaxError: i ...

  5. 关于 php 和 python 的浮点计算 0.1+0.2

    关于 php 和 python 的浮点计算 0.1+0.2 看到群里有小伙伴说为什么 python 计算出 0.1+0.2 是 0.30000000000000004 >>> pri ...

  6. 在 Ubuntu 16.04 LTS 上安装 Python 3.6.0

    原文连接:https://segmentfault.com/a/1190000007912666 最近 Python 3 发布了新版本 Python 3.6.0,好像又加入了不少黑魔法!- 由于暂时不 ...

  7. Win7 64bit+Anaconda(3-5.0.1,Python3.6)+Pycharm(community-2017.3.3)+OpenCV(python‑3.4.0‑cp36‑cp36m)(转载)

    Anaconda(3-5.0.1,Python3.6)下载链接:https://pan.baidu.com/s/1bqFwLMB 密码:37ih Pycharm(community-2017.3.3) ...

  8. Python3.6中文文档 又来推荐一个,之前的Python3.52看得有点懵逼 https://www.rddoc.com/doc/Python/3.6.0/zh/

    https://www.rddoc.com/doc/Python/3.6.0/zh/    大家有空看下

  9. New in Python 3.8.0

    Python 3.8.0 发布时间: Oct. 14, 2019 这是一个Python3.8.0的稳定发行版. Python3.8.0是最新的Python编程语言发行版,ta包含了许多新的特征和优化. ...

随机推荐

  1. crontab定期执行shell脚本

    [场景]: 需要定期运行Hadoop的MapReduce [解决办法]: 编写一个运行MapReduce的Shell脚本.然后使用crontab配置定时任务. [Shell脚本] #!/usr/bin ...

  2. quartz.net结合Topshelf实现windows service服务托管的作业调度框架

    topshelf可以很简单方便的实现windows service服务,详见我的一篇博客的介绍 http://www.cnblogs.com/xiaopotian/articles/5428361.h ...

  3. yii2项目实战-路由美化以及如何正确的生成链接

    yii2项目实战-路由美化以及如何正确的生成链接 更新于 2016年12月17日 by 白狼 被浏览了 705 次 美化路由 何为美化路由呢?美化嘛,无外乎就是给路由化化妆,让她好看点.我虽没化过妆, ...

  4. ios7 - Custom UItabbar has a gap in the bottom

    3down votefavorite   Im trying to create a custom UITabbar using images for the selected and unselec ...

  5. spring mvc 入门程序

    入门程序 1.环境准备 myeclipse Spring jar 2.前端控制器设置 (web.xml) 所有的*.action请求通过org.springframework.web.servlet. ...

  6. SQL语句统计错误率

    2018年的第一篇博客就以此作为开端吧 :D 最近在项目中碰到需要统计类似错误率之类的需求,原本这功能是之前做的,但是最近测的时候发现出了点问题,显示的结果不对.这就比较尴尬了... 于是就进行deb ...

  7. 第二章第一个项目——关于mime

    一句话就能解释清楚. MIME标注HTTP响应类型. 而后缀名标注文件类型. ---------分割线-------- http响应实质上只有数据,没有文件名. 举个例子吧. HTTP/1.1 200 ...

  8. 13、Semantic-UI之表格与表单

    13.1 定义基础样式表格   在HTML中可以通过table进行表格定义,在Semantic-UI中也可以通过class="ui table"定义表格. 示例:定义基础表格 &l ...

  9. JavaScript函数参数问题

    声明一个回调函数 function(){ alert(data); } 这个时候,若调用这个函数的传入了一个同名data,则这里会引用到data的值,因为他们处于同一作用域.

  10. EasyUI combobox动态增加选择项

    有需求需要动态的为combobox增加可选项,后来解决方案如下 html如下 <select id="workerList"></select> js 如下 ...