kamacoder-solutions icon indicating copy to clipboard operation
kamacoder-solutions copied to clipboard

A+B问题III中给出的Python代码不具有普适性

Open BingxingDong opened this issue 1 year ago • 0 comments

在A+B问题III中的Python代码中:


import sys

while True: s = input().split() # 一行一行读取 a, b = int(s[0]), int(s[1]) if not a or not b: # 遇到 0, 0 则中断 break print(a + b)


该模板只适用于当前题型,a,b= int(s[0]), int(s[1]),再加上后面的判断 if not a or not b ,这两行代码并不具有普适性,如果改为:


import sys

while True: s = list(map(int,input().split())) # 一行一行读取 if not any(s): break # 遇到 0, 0 则中断 print(sum(s))


这里面的if not any(s): break 具有普适性,希望建议能被采纳!!

BingxingDong avatar Sep 18 '23 14:09 BingxingDong