【发布时间】:2020-10-03 00:36:39
【问题描述】:
喜欢 1234,4566,654,987;我们看到,我们有 4 和 6 都以 3 作为频率。因此,我们将收到 6 的输出,因为它更大。 所以,我认为作为解决方案的代码是:
def MaxDigit(input1,input2,input3,input4):
arr=[input1,input2,input3,input4]
k=0
for i in range(1,10):
ask=[0]*i
for j in range(0,4):
while arr[j]!=0:
k=int(arr[j]%10)
arr[j]=int(arr[j]/10)
ask[k]+=1
因此,在此之后,我们将获得 ask 列表,其中 no.s 为索引,频率为 value。我可以进一步编码。 但它显示 last line 的 index out of range 错误,即 ask[k]+=1 我无法猜测,为什么它会这样显示。请帮我解决一下这个。 如果也有替代代码,请帮助我。
【问题讨论】:
-
no.s???....... -
表示数字。
-
我得到了合适的代码,但谁能告诉我它在我的代码中显示索引超出范围错误的原因? @尼克
-
@goodvibration 你能告诉我代码中出现索引错误的原因吗?
标签: python list index-error frequency-analysis indexoutofrangeexception