Python题解 | #记负均正#

记负均正

https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8

import sys



while True:
    try:
        a = int(input())
        nums = list(map(int, input().split(' ')))
        res = []
        ans = 0
        s = 0.0
        x = 0.0
        flag = 0
        for i in nums:
            if i != 0:
                res.append(i)
            if i < 0:
                ans += 1
            if i != 0 and i > 0:
                flag += 1
                s += i
        if flag == 0:
            x = 0.0
        else:
            x = s / flag
        print(ans, end=' ')
        print('%.1f' % x)
    except:
        break

全部评论
注意正数为0的情况,除数为0,可以单独判断
点赞
送花
回复 分享
发布于 05-18 21:57 上海

相关推荐

//鲨鱼辣椒:这我活集贸啊,跳了 ━━━━━┒ ┓┏┓┏┓ I ┛┗┛┗┛┃\🤡/ ┓┏┓┏┓┃ / ┛┗┛┗┛┃ノ) ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┃┃┃┃┃┃ ┻┻┻┻┻┻🌳🌳🌳🌳🌳🌳
投递小米集团等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务