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. ubuntu下学习linux

    ---恢复内容开始--- 查看当前正在运行的进程(ps命令, grep 搜索命令) ps -ef # -e 显示所有进程,环境变量 -f 全格式 也可以用: ps -e -f # 显示所有关于java ...

  2. mysql 用户创建,修改和忘记root密码的操作

    #创建用户CREATE USER 'zzq'@'localhost' IDENTIFIED by 'zzq';#flush privileges 命令本质上的作用是将当前user和privilige表 ...

  3. OBD Problem Vehicles

    This page contains a list of vehicles that are known to be non-compliant with OBD-II in one way or a ...

  4. PM2部署资料

    问题1:pm2的log怎么查看?(pm2 show (name))可以看到日志地址,直接查看 问题2:日志怎么清除:pm2 flush 问题3:修改日志输出路径 问题4:怎么重新加载,restart貌 ...

  5. C++11新特性之auto

    auto的使用  c++11引入了auto类型说明符,auto让编译器通过初始值来推算变量的类型,所以auto定义的变量必须有初始值.  使用auto也能在一条语句中声明多个变量,因为一条声明语句只能 ...

  6. php 导出csv表格文件

    1.数据库取出数据,存放在二维数组中 $conn=new mysqli('localhost','root','root','myDBPDO'); $result=$conn->query('s ...

  7. HDU 2602 Bone Collector (01背包DP)

    题意:给定一个体积,和一些物品的价值和体积,问你最大的价值. 析:最基础的01背包,dp[i] 表示体积 i 时最大价值. 代码如下: #pragma comment(linker, "/S ...

  8. Word 2010发布博客文章(修正)

    目前大部分的博客作者在写博客这件事情上都会遇到以下3个痛点:1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.2.发布到博客或公众号平台 ...

  9. xfce4快捷键设置

    xfce4的"Keyboard"可以方便的设置启动应用程序的快捷键. 例如,添加xfce4-terminal和emacs的启动快捷键 Alt+F3打开"Applicati ...

  10. Linux下MySQL表名不区分大小写的设置方法

    MySQL表名不区分大小写的设置方法 在用centox安装mysql后,把项目的数据库移植了过去,发现一些表的数据查不到,排查了一下问题,最后发现是表名的大小写不一致造成的. mysql在window ...