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("? + ? = ?")