pat L1-025正整数A + B(python3)
思路:暴力解题,输入正确格式,使用isdecimal函数判断,然后进行输出。import mathA,B = input().split()#输入两个数c = int(A) + int(B)count_a = True#A是否为正整数的记号count_b = True#B是否为正整数的记号if A.isdecimal():..
·
思路:暴力解题,输入正确格式,使用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("? + ? = ?")
更多推荐
已为社区贡献3条内容
所有评论(0)