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. STM32F4通用定时器

    1.基本原理 三种定时器区别 通用定时器功能特点描述 在这里只用输入捕获事件也能获取脉冲个数同时可以只使用它来获取脉冲宽度,比如当捕获到上升沿,马上进入中断,把计数器的值置零,然后等待捕获下降沿的到来 ...

  2. Mac os安装DVWA环境教程

    Mac os安装DVWA环境教程 1.尽管Mac自带Apache和php 事实上Mac和WIN都用XAMPP一键化安装比较方便 2.解压DVWA-master 改名为dvwa移动到XAMPP的目录 3 ...

  3. Word2013文章如何直接发布到CSDN博客

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

  4. Android 内存优化[转]

    一. Android的内存机制 Android的程序由Java语言编写,所以Android的内存管理与Java的内存管理相似.程序员通过new为对象分配内存,所有对象在java堆内分配空间:然而对象的 ...

  5. ARM汇编程序中的伪指令

    转自http://blog.chinaunix.net/uid-13701930-id-336459.html 4.1 ARM汇编器所支持的伪指令 在ARM汇编语言程序里,有一些特殊指令助记符,这些助 ...

  6. 安装Python-Windows

    安装Python-Windows 在开始Python编程前,需要先安装Python环境.Python安装包可以到Python的官网下载,官网地址是https://www.python.org/,如果想 ...

  7. Linq的使用场景简介和认识

    一:C#的一个分支Linq 二:学Linq需要有一些基础知识 1. var 隐式类型 2. 匿名类型/匿名方法 3. 自动属性 4. 委托/泛型的委托 5. lambda 6. 扩展方法 7. 对象初 ...

  8. 利用PhotoShop对大图像进行等分切片

    图文介绍利用PhotoShop等分切图 1.调用切片工具,右键选择划分切片 2.指定水平划分.垂直划分的等分数量,点击确定 3.在文件菜单中选择存储为... 4.配置图像质量参数.点击存储.指定存储位 ...

  9. [自动化专题]JDBC操作mysql时遇到的拦路虎

    在挫折中成长,在错误中学习.聊聊我们在Selenium自动化中使用JDBC操作mysql数据库中遇到的那些拦路虎: 错误一:Can not issue data manipulation statem ...

  10. Win7系统下搭建FTP

    一.创建FTP站点  1.打开:控制面板---系统和安全---管理工具---Internet 信息服务 2. 建站:右键点击网站---添加FTP站点 3. 输入FTP 站点名称---选择你的 FTP ...