使用Python实现计算器功能
来源:互联网 发布:2017最污的网络词 编辑:程序博客网 时间:2024/06/06 02:20
实现目标:使用Python完成,输入两个数,得到加减乘除余结果的功能,其中结果输出使用不同的格式。
Python版本为3.6.0
1. 定义两个变量a,b,使用键盘输入的方式。python的2.x版本中键盘输入有两种方式可以实现:raw_input(),input(),在3.X版本中两者合并为一个,只支持input().
2. 输出结果:
(1) 输出string型的结果
print("A+B = %s"%(a+b)) # output string(2) 输出int型的结果:默认格式,占位符格式,填充占位符格式,靠左格式
print("A-B = %d"%(a-b)) # output intprint("A-B = %4d"%(a-b)) print("A-B = %04d"%(a-b)) print("A-B = %-4d"%(a-b))结果:a=7,b=3A-B = 4A-B = 4A-B = 0004A-B = 4
(3) 输出为浮点数类型:默认格式,限制小数位数格式,占位符及限制小数位数格式
print("A*B = %f"%(a*b)) # output floatprint("A/B = %.2f"%(a/b)) # output float of two decimal placesprint("A/B = %05.2f"%(a/b)) # output float of two decimal places结果:a=7,b=3
A*B = 21.000000
A/B = 2.33
A/B = 02.333. 全部实现,开发工具为pycharm
# calculatea = int(input("Please input number A:"))b = int(input("Please input number B:"))print("A+B = %s"%(a+b)) # output stringprint("A-B = %d"%(a-b)) # output intprint("A*B = %f"%(a*b)) # output floatprint("A/B = %.2f"%(a/b)) # output float of two decimal placesprint("A%B"+" = %06d"%(a%b)) # output int of 6 bit placeholder filled with 0print("A与B和是%s,差是%d,乘积是%02.2f,商是%-4.2f,余数是%03d"%(a+b,a-b,a*b,a/b,a%b))
阅读全文
1 0
- 使用Python实现计算器功能
- Python---计算器功能实现
- python实现栅格计算器功能
- python----------------正则实现计算器功能
- Python+MoneyRunner+Java实现计算器功能自动化
- Python使用wxPython实现计算器
- 使用JSP和javabean实现计算器功能
- 使用 js 实现 贷款计算器功能
- 利用Python实现ARCGIS中栅格计算器的简单功能
- Python实现ARCGIS栅格计算器con函数功能
- python编程练习---一行代码实现计算器功能
- 计算器功能简单实现
- Android实现计算器功能
- 实现计算器功能
- android实现计算器功能
- UI04 实现计算器功能
- 计算器功能实现
- JavaScript实现计算器功能
- Android实现发送一条有序广播
- Unity 立体3D VR的实现
- 程序员_你可以更健康!
- 网站建设和网站运营需要样注意什么?
- 奥威Power-BI 旅游业BI方案——按省份分析旅游情况
- 使用Python实现计算器功能
- UE4引擎Bulid打包失败UnrealBuildTool Exception: System.IO.IOException:
- [转载]Intent中的四个重要属性——Action、Data、Category、Extras
- 基于物理的渲染—HDR Tone Mapping
- C++ Primer Plus(第六版)—— 第二章 开始学习C++ 笔记
- Sub-1GHz
- EAS8.0,EAS8.2,WAF2,JS,打开新页面,打开新窗口,传递参数
- Deep CORAL: Correlation Alignment for Deep Domain Adaptation(2016)
- Linux下比较常用的svn命令