思路:暴力解题,输入正确格式,使用isdecimal函数判断,然后进行输出。

import math


A,B = input().split()                   #输入两个数
c = int(A) + int(B)
count_a = True                          #A是否为正整数的记号
count_b = True                          #B是否为正整数的记号

if A.isdecimal():                       #isdecimal()是判断是否为正整数
    count_a = True
else:
    count_a = False

if B.isdecimal():
    count_b = True
else:
    count_b = False

    
#A,B的四种情况
if count_a == False and count_b:
    print(f"? + {B} = ?")
    
if count_a and count_b == False:
    print(f"{A} + ? = ?")

if count_a and count_b :
    print(f"{A} + {B} = {c}")

else:
    print("? + ? = ?")
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐