大佬教程收集整理的这篇文章主要介绍了我如何实现一个函数,该函数根据 A 和 B = 总数中的零数之和来检查所有整数对 X 和 Y?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
因此,我正在尝试实现一个函数,它将检查所有整数对 A 和 B,使得 A 和 B 中的零数之和 = 总数。所以,例如,如果
def compare(numbers,@R_95_10586@l):
if (condition):
return True #it will return True if exists two numbers A and B in the List
return false #it will return false if the two numbers does not exist in the List
numbers = [10,600,81000,2100000]
@R_95_10586@l = 5 #the @R_95_10586@l number of zeroes we want
print(compare(numbers,@R_95_10586@l))
我们可以看到@R_95_10586@l = 5,所以我们需要返回列表中的一对数字,使得两个数字中零的数量与5个零的总数相对应。因此,通过该函数,它应该显示 A = 600 和 B = 81000,因为 A 和 B 中的零之和 = 5(A 中的 2 + B 中的 3)。如果在列表中找不到 A 和 B 的零之和,例如如果 @R_95_10586@l = 6 含义(A 中的零 + B 中的零 = 6),则应显示 A 和 B 未找到并返回 false。>
您可以执行以下操作:
def compare(SEQ,z):
for i in SEQ:
for k in SEQ:
if str(i).count('0')+str(k).count('0') ==Z:
return True
else:
conTinue
return false
,
好吧,逻辑有点复杂,但工作正常
def compare(numbers,@R_95_10586@l):
all_list = []
for i in numbers:
zeros = str(i).count("0")
if zeros > 0:
remaining_zeros = @R_95_10586@l - zeros
if remaining_zeros > 0:
for j in numbers:
if str(j).count("0") == remaining_zeros:
all_list.append((i,j))
return all_list
numbers = [10,600,81000,210000]
@R_95_10586@l = 5 #the @R_95_10586@l number of zeroes we want
print(compare(numbers,@R_95_10586@l))
以上是大佬教程为你收集整理的我如何实现一个函数,该函数根据 A 和 B = 总数中的零数之和来检查所有整数对 X 和 Y?全部内容,希望文章能够帮你解决我如何实现一个函数,该函数根据 A 和 B = 总数中的零数之和来检查所有整数对 X 和 Y?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。