话不多说,直接上代码:
result = sum([int(i) for i in input().split(' ')])
result = str(result)[::-1]
output = ''
for index, word in enumerate(result):
if index != 0 and index % 3 == 0 and word != '-':
output += ','
output += word
print(output[::-1])
先求和,然后反转字符串,条件满足就加个逗号,最后再反转字符串输出,ok

本文介绍了一种简洁的方法,通过Python代码实现输入字符串求和后反转,并按特定条件添加逗号,适用于快速处理字符串操作。

被折叠的 条评论
为什么被折叠?



