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. Spring思维导图(IOC篇)

    写在前面 写过java的都知道:所有的对象都必须创建:或者说:使用对象之前必须先创建.而使用ioc之后,你就可以不再手动创建对象,而是从ioc容器中直接获取对象. 就好像我们无需考虑对象的销毁回收一样 ...

  2. functions函数插件的定义和使用

    创建Smarty插件:在插件目录(plugins)里新建文件 类型.插件名.php文件,然后插件方法名字书写规范: smarty_类型_插件名([...]){}在模板(tpl文件)中调用插件时格式{插 ...

  3. centos7如何知道jdk的在哪个目录

    今天一个小实验需要安装jdk,用命令Java -version查询了一下,原来Centos7自带OpenJDK的环境,但是需要手动配置/etc/profile文件,于是开始找java的安装路径.... ...

  4. Linux学习系列——零基础开始

    第一部分 Linux基础命令 1.查看系统信息命令 2.Linux内核版本 3.修改环境变量

  5. crontab基本操作部分

    一.cron服务 cron是一个linux下 的定时执行工具,可以在无需人工干预的情况下运行作业. service crond start    //启动服务 service crond stop  ...

  6. 从源码角度看Transaction以及如何手工接管Transaction实现高度的自定义化

    一:transaction CUD: 在一个transaction中... transaction: start add.... delete... update... transaction: co ...

  7. error: field 'b' has imcomplete type

    在下面的程序中,在编译时会遇到下面的错误: error: field 'b' has incomplete type 域b是一个不完备的类型,即class B的声明不完备 #include <i ...

  8. [Erlang11] 那些经历过的Erlang小坑11-20

    11.每次重装系统时都会重新安装Erlang,Ubuntu安装sh秒杀一切. https://gist.github.com/zhongwencool/11174620 12. Erlang Shel ...

  9. HBase介绍(3)---框架结构及流程

    HBASE依托于Hadoop的HDFS作为存储基础,因此结构也很类似于Hadoop的Master-Slave模式,Hbase Master Server 负责管理所有的HRegion Server,但 ...

  10. C#线程/进程同步(lock、Mutex、Semaphore)

    一.lock(实质是Monitor.Enter和Monitor.Exit)(线程同步) 二.Mutex(互斥量)(线程/进程同步) Mutex有个好的特性是,如果程序结束时而互斥锁没通过Release ...