码迷,mamicode.com
首页 > 其他好文 > 详细

成绩统计

时间:2021-04-19 15:57:59      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:form   截取   int   format   com   lock   png   inpu   for   

6.成绩统计(15)

  • 对给定人数的成绩输出其及格率和优秀率(百分号前保留整数)

  • n = int(input())
    a,b=0,0
    for i in range (n):
        s = int(input())
        if s>=60:
            a+=1
        if s>=85:
            b+=1
    print(‘{:.0%}‘.format(a/n))
    print(‘{:.0%}‘.format(b/n))
    
    
  • 结果

技术图片

  • ps

1.截取字符串:‘{:.5}‘.format(‘Hello Chen‘) # 截取前5个字符-----Hello

2.数字格式化:print("{:.2f}".format(3.1415926))-----输出3.14

3.使用逗号作为千位分隔符:print(‘{:,}‘.format(1234567890))-----输出‘1,234,567,890‘

4.表示一个百分比:print(‘ {:.2%}‘.format(0.61898))------输出61.90%

5.时间格式化:import datetime

d = datetime.datetime(2018, 7, 31, 15, 58, 58)

print(‘{:%Y-%m-%d %H:%M:%S}‘.format(d))----输出2018-07-31 15:58:58

成绩统计

标签:form   截取   int   format   com   lock   png   inpu   for   

原文地址:https://www.cnblogs.com/lushuang55/p/14671016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!