L1-025 正整数A+B

题目详情

题的目标很简单,就是求两个正整数AB的和,其中AB都在区间[1,1000]。稍微有点麻烦的是,输入并不保证是两个正整数。

输入格式

输入在一行给出AB,其间以空格分开。问题是AB不一定是满足要求的正整数,有时候可能是超出范围的数字、负数、带小数点的实数、甚至是一堆乱码。

注意:我们把输入中出现的第1个空格认为是AB的分隔。题目保证至少存在一个空格,并且B不是一个空字符串。

输出格式

如果输入的确是两个正整数,则按格式A + B = 和输出。如果某个输入不合要求,则在相应位置输出?,显然此时和也是?

输入样例

123 456

输出样例

123 + 456 = 579

代码展示

A,B=input().split(maxsplit=1)
if A.isdigit() and B.isdigit() and 1000>=int(A)>=1 and 1000>=int(B)>=1:
    print(f"{A} + {B} = {int(A)+int(B)}")
elif not A.isdigit() and B.isdigit() and 1000>=int(B)>=1:
    print(f"? + {B} = ?")
elif A.isdigit() and B.isdigit() and (1000<int(A) or int(A)==0) and 1000>=int(B)>=1:
    print(f"? + {B} = ?")
elif A.isdigit() and B.isdigit() and 1000>=int(A)>=1 and (1000<int(B) or int(B)==0):
    print(f"{A} + ? = ?")
elif A.isdigit() and not B.isdigit() and  1000>=int(A)>=1:
    print(f"{A} + ? = ?")
else:
    print("? + ? = ?")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值