获取圆周率不同的精度

import math
for precision in range(10):
    print round(math.pi,precision)

int,round,math.floor的不同之处

  • 函数int()直接截去小数部分,返回整型。
  • 函数floor()得到最接近原数但小于原数的浮点数
  • 函数round()接四舍五入的方式取精确度,返回浮点数。
import math for n in (.2, .7, 1.2, 1.7, -.2, -.7, -1.2 ,-1.7): print "int(%.1f)\t%+.1f" % (n, int(n)) print "floor(%.lf)\t%+.lf" % (n,math.floor(n)) print "round(%.lf)\t%+.lf" % (n,round(n)) print '-' * 20

输入一个测试成绩,根据下面的标准,输出他的评分成绩(A—E)

  • A:90~100
  • B:80~89
  • C:70~79
  • D:60~69
  • E:

# coding='utf-8'
n = raw_input("请输入一个0~100的分数")
n = int(n)
if 90   

输入一个年份,判定其是否闰年


year = raw_input('请输入要检测的年份')
year = int(year)
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
    print year ,'是闰年'
else:
    print year ,'不是闰年'

取一个任意小于1美元的金额,然后计算可以转换成最小多少枚硬币.硬币有1美分,5美分,10美分,25美分4种.1美元等于100美分.举例说,0.76美元换算结果应该为3枚25美分,1枚1美分.类似76枚1美分,2枚25美分+2枚10美分+1枚5美分+1枚1美分的结果是不合要求的!


# coding='utf-8'

n = raw_input("请输入一个小于1美元的金额")
n = int(float(n) * 100)
ret = ''
for i in (25, 10, 5, 1) :
    if i 

JS是数组join字符串,python是字符串join数组

相关文章:

  • 2021-10-26
  • 2021-09-14
  • 2022-12-23
  • 2021-10-16
  • 2021-10-18
  • 2021-10-28
  • 2021-10-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2021-10-27
相关资源
相似解决方案