L1-025 正整数A+B python

python 实现

注:输入的数据需要在区间 [1,1000] 内

s=input()
loc=s.index(" ")

a=s[:loc]
b=s[loc+1:]

if a.isdecimal() and b.isdecimal():
    if int(a) in [i for i in range(1,1001)] and int(b) in [i for i in range(1,1001)]:
        print("{a} + {b} = {sum}".format(a=a, b=b, sum=int(a) + int(b)))
    elif int(a) in [i for i in range(1,1001)]:
        print("{a} + ? = ?".format(a=a))
    elif int(b) in [i for i in range(1,1001)]:
        print("? + {b} = ?".format(b=b))
    else:
        print("? + ? = ?")
elif a.isdecimal():
    if int(a) in [i for i in range(1,1001)]:
        print("{a} + ? = ?".format(a=a))
    else:
        print("? + ? = ?")
elif b.isdecimal():
    if int(b) in [i for i in range(1,1001)]:
        print("? + {b} = ?".format(b=b))
    else:
        print("? + ? = ?")
else:
    print("? + ? = ?")

 

posted @ 2024-06-30 20:54  豆豆是只乖狗狗  阅读(17)  评论(0编辑  收藏  举报