我正在解决一个问题,在检查一个数字是否是独眼巨人的数字后,我需要返回True或False。一个独眼巨人数字由奇数个数字组成,只有10个,零位于中间。以下是我目前掌握的情况:
def is_cyclops(n):
strNum = str(n)
for i, el in enumerate(strNum):
if(len(strNum) % 2 == 0):
return False
else:
# find middle number is zero
# no other zeros exist
# return True
is_cyclops(0) # True
is_cyclops(101) # True
is_cyclops(1056) # False
is_cyclops(675409820) # False
我如何找到中位数(不使用numpy)&;确保它是零,并且它是该数字中唯一存在的零
这对我很有用:
输出:
看来你在这里做了很好的尝试,我会帮你的
相关问题 更多 >
编程相关推荐