a和b是整数,计算a/b的百分比

a=3

b=7

a=float(a)

b=float(b)

保留百分比后2位小数

print  "%.2f%%" % (a/b*100)

'42.86%'

保留百分比后1位小数

print  "%.1f%%" % (a/b*100)

'42.9%'

保留百分比

print  "%.f%%" % (a/b*100)

'43%'

python计算两个数的百分比的更多相关文章

  1. LeetCode 29 Divide Two Integers (不使用乘法,除法,求模计算两个数的除法)

    题目链接: https://leetcode.com/problems/divide-two-integers/?tab=Description   Problem :不使用乘法,除法,求模计算两个数 ...

  2. Python编写两个数的加减法游戏

    目标: 1.实现两个数的加减法 2.回答者3次输错计算结果后,输出正确结果,并询问回答者是否继续 1.使用常规函数实现两个数的加减法游戏 代码如下: #!/usr/bin/env python # - ...

  3. python 计算两个日期相差多少个月

    近期,由于业务需要计算两个日期之前相差多少个月.我在网上找了很久,结果发现万能的python,居然没有一个模块计算两个日期的月数,像Java.C#之类的高级语言,都会有(date1-date2).mo ...

  4. js求两个数的百分比

    function toPercent(num, total) { return (Math.round(num / total * 10000) / 100.00 + "%");/ ...

  5. 【LintCode】计算两个数的交集(二)

    问题分析: 用两个指针分别遍历即可. 问题求解: public class Solution { /** * @param nums1 an integer array * @param nums2 ...

  6. 【LintCode】计算两个数的交集(一)

    问题分析: 既然返回值没有重复,我们不妨将结果放进set中,然后对两个set进行比较. 问题求解: public class Solution { /** * @param nums1 an inte ...

  7. python 取两数的百分比

    Python (r266:, Jan , ::) [GCC (Red Hat -)] on linux2 Type "help", "copyright", & ...

  8. java 求 两个数的百分比% (转)

    int num1 = 7; int num2 = 9; // 创建一个数值格式化对象 NumberFormat numberFormat = NumberFormat.getInstance(); / ...

  9. python计算两个日期时间差

    经常在python中因为日期而google,在此做个小笔记. >>>import datetime >>> a = datetime.date.today() &g ...

随机推荐

  1. 使用STM32CubeMX生成RTC工程[闹钟中断]

    使用的硬件为正点原子的MINISTM32. 需要主要注意: STM32F1系列 <UM1850 User manual Description of STM32F1xx HAL drivers ...

  2. office转pdf转swf

    系统环境:CentOs5.5用到的工具:Openoffice 3 , Pdf2Swf tool , Jodconverter , FlexPaper 网上找了些资料,早有人已经实现了这样的功能,只不过 ...

  3. as3调用外部应用程序 as调用外部exe文件as3调用bat文件 未测试

    private function callTest(event: Event): void{callExe("d:/a.exe");callBat("d:/a.bat&q ...

  4. 使用ssh密钥登录虚拟主机里的另一台主机报警的解决方案

    提示:Address 192.168.*.* maps to localhost, but this does not map back to the address - POSSIBLE BREAK ...

  5. Zookpeer集群节点

    Adaptive Communication Environment(自适配通信环境),简称ACE. reference artfile:zookeeper单节点与集群的安装https://blog. ...

  6. redis异常和注意点

    目录: 1. 修改配置不起作用 2.Connection reset by peer: socket write error 3. redis-cli 查看中文乱码 1. 修改配置不起效果 我们修改了 ...

  7. C#中关于@的用法

    1. 加在字符串前面,字符串中的 \ 失去转义符的作用,直接写字符串而不需要考虑转义字符 string path = @"C:\Windows\"; // 如果不加 @,编译会提示 ...

  8. curator 实现分布式一致性锁

    最近准备在项目中引入分布式锁,故而研究基于zookeeper的curator框架. 网上资料不多,自己研究其源码发现,这个框架已经帮我做了很多现成的实现. 下面介绍下锁的实现: 通过源码中Lockin ...

  9. 4.ClassLink - 一种新型的VPC 经典网络的连接方式

    阿里云CLassLink文档地址:https://help.aliyun.com/document_detail/65412.html?spm=a2c4g.11186623.2.9.41a25a07F ...

  10. Kibana安装与基本用法(ELK)

    强制使用smtp 465端口加密发送邮件: vim kibana.yml 添加如下: sentinl: settings: email: active: true user: wjoyxt@.com ...