python四则运算2.0
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的更多相关文章
- Python 3.6.0的sqlite3模块无法执行VACUUM语句
Python 3.6.0的sqlite3模块存在一个bug(见issue 29003),无法执行VACUUM语句. 一执行就出现异常: Traceback (most recent call last ...
- 结对子作业 四则运算 V2.0
import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import ja ...
- Apache Qpid Python 1.35.0 发布
Apache Qpid Python 1.35.0 发布了,Apache Qpid (Open Source AMQP Messaging) 是一个跨平台的企业通讯解决方案,实现了高级消息队列协议.提 ...
- python 3.4.0 简单的print 'hello world',出错--SyntaxError: invalid syntax
问题描写叙述: win7下安装的python 3.4.0版本号, 在命令行里写入简单的输出语句: print 'hello world' 然后enter,结果返回结果为: SyntaxError: i ...
- 关于 php 和 python 的浮点计算 0.1+0.2
关于 php 和 python 的浮点计算 0.1+0.2 看到群里有小伙伴说为什么 python 计算出 0.1+0.2 是 0.30000000000000004 >>> pri ...
- 在 Ubuntu 16.04 LTS 上安装 Python 3.6.0
原文连接:https://segmentfault.com/a/1190000007912666 最近 Python 3 发布了新版本 Python 3.6.0,好像又加入了不少黑魔法!- 由于暂时不 ...
- 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) ...
- Python3.6中文文档 又来推荐一个,之前的Python3.52看得有点懵逼 https://www.rddoc.com/doc/Python/3.6.0/zh/
https://www.rddoc.com/doc/Python/3.6.0/zh/ 大家有空看下
- New in Python 3.8.0
Python 3.8.0 发布时间: Oct. 14, 2019 这是一个Python3.8.0的稳定发行版. Python3.8.0是最新的Python编程语言发行版,ta包含了许多新的特征和优化. ...
随机推荐
- JavaWeb项目导入MyEclipse后变为JAVA项目项目【解决方法】
问题描述:之前有个项目是Java web的项目,但是后来我导入到我电脑里的myEclipse里后就变成了Java项目.查找了资料解决了,网上大部分都是说在eclipse里解决这个问题,在myEclip ...
- 敏捷开发之XP
敏捷方法论有一个共同的特点,那就是都将矛头指向了“文档”,它们认为传统的软件工程方法文档量太“重”了,称为“重量级”方法,而相应的敏捷方法则是“轻量级”方法.正是因为“轻量级”感觉没有什么力量,不但不 ...
- kalilinux基础
service postgresql start service metasploit start msfconsole-db_status 配置metasploit随系统启动: update-rc. ...
- up6-自定义文件存储路径
在up6.2中有两种保存模式,一种是md5一种是uuid. md5由PathMd5Builder生成存储路径.md5主要提供给文件使用,可在服务器端保存唯一的文件,有效避免重复文件. uuid由Pat ...
- 敏捷软件开发:原则、模式与实践——第13章 写给C#程序员的UML概述
第13章 写给C#程序员的UML概述 UML包含3类主要的图示.静态图(static diagram)描述了类.对象.数据结构以及它们之间的关系,藉此表现出了软件元素间那些不变的逻辑结构.动态图(dy ...
- 设计模式8---适配器模式(Adapter)
1. 适配器模式简介 适配器模式(Adapter):将一个类的接口转换成客户希望的另外一个接口.Adapter 模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 适用场景: 1.已经存在 ...
- Hexo 最常用的几个命令
Hexo 约有二十个命令,但普通用户经常使用的大概只有下列几个: hexo s hexo s 启动本地服务器,用于预览主题.默认地址: http://localhost:4000/ hexo s 是 ...
- github 上中国互联网公司的开源项目
github上 那个 watch和 follow功能 不太好用啊. 是我用的 不好,还是 怎么的.有时候 找不到 watch 和 follow. 秉持 开源 精神,省的大家 和 我 查找. 我只关注 ...
- [LeetCode 题解]: Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- 读取IE缓存文件
使用WebCacheTool项目中的WinInetAPI.cs和Win32API.cs两个类 /// <summary> /// 获取IE缓存文件 /// </summary> ...