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包含了许多新的特征和优化. ...
随机推荐
- jQuary总结11:jQuery插件封装---jQuery封装 手风琴 动画插件
完整代码下载点击我的GitHub: https://github.com/XingJYGo/jquery-accordion 1 手风琴的效果展示如下: 2 封装插件目录结构如下: 主要包括:HTML ...
- 编写高质量代码改善C#程序的157个建议——建议88:并行并不总是速度更快
建议88:并行并不总是速度更快 并行所带来的后台任务及任务的管理,都会带来一定的开销,如果一项工作本来就能很快完成,或者说循环体很小,那么并行的速度也许会比非并行要慢. 看这样一个例子,我们比较在同步 ...
- 字节序(Endian),大端(Big-Endian),小端(Little-Endian)
http://www.cppblog.com/tx7do/archive/2009/01/06/71276.html 在各种计算机体系结构中,对于字节.字等的存储机制有所不同,因而引发了计算机通信领域 ...
- 关于iReport中纸张的大小 换算
在iReprot里中进行报表设计时 第一步先确定纸张的大小 如A4纸 直接选就行了 A2 A3一样的,但还会在这种情况这种纸没有选择的怎么办? 比如 那种代小孔的纸 279*241m ...
- 团体程序设计天梯赛L1-027 出租 2017-03-23 23:16 40人阅读 评论(0) 收藏
L1-027. 出租 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 下面是新浪微博上曾经很火的一张图: 一时间网上一片求救声, ...
- hibernate缓存机制(转载)
缓存是介于应用程序和物理数据源之间,其作用是为了降低应用程序对物理数据源访问的频次,从而提高了应用的运行性能.缓存内的数据是对物理数据源中的数据的复制,应用程序在运行时从缓存读写数据,在特定的时刻或事 ...
- DLL用def定义文件来导出重载函数(转)
动态链接库DLL_Sample.dll DLL_Sample.h:#ifdef TEST_API# define TEST_API _declspec(dllexport)#else# define ...
- js 操作cookie cookie路径问题
这里主要不是讲这个方法,js写cookie这种代码网上一抓一把,在使用的时候遇到一点问题,就是写的cookie 是有路径问题的,在user目录下可以使用跳转到另外一个目录下cookie,经过比较coo ...
- 【转】生活中的OO智慧——大话面向对象五大原则
原文地址:http://www.cnblogs.com/aoyeyuyan/p/4388110.html 一·单一职责原则(Single-Responsibility Principle) 定义:一个 ...
- Partition--分区切换2
有分区表TB2和TB2_History CREATE TABLE TB2( ID BIGINT IDENTITY(1,1) PRIMARY KEY, C1 NVARCHAR(200))ON[ps_T ...