栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python-PAT甲级题解-1001

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python-PAT甲级题解-1001

Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

Input Specification:

Each input file contains one test case. Each case contains a pair of integers a and b where −106≤a,b≤106. The numbers are separated by a space.

Output Specification:

For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

Sample Input:
-1000000 9

结尾无空行

Sample Output:
-999,991

结尾无空行

Sample Solution:
if __name__ == '__main__':
    arr=input().split()
    a=int(arr[0])
    b=int(arr[1])
    c=a+b
    re=str(c)
    for i in range(len(re)):
        print(re[i],end="")
        t=len(re)-i-1
        if re[i]=='-':
            continue
        if t!=0 and t%3==0:
            print(',',end="")

附提交结果

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/331173.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号