python3求助

P1591 阶乘数码

LanQiDongLai @ 2021-07-26 18:18:03

def fact(num):
    sum = 1
    for i in range(1, num + 1):
        sum*=i
    return sum
a = int(input())
for i in range(0, a):
    strnum = input().split(' ')
    d = str(fact(int(strnum[0])))
    sum = 0
    for j in d:
        if j == strnum[1]:
            sum += 1
    print(sum)

样例都过了,数据点全爆零,而且每个数据点都显示第一列第一行读到字符0


by 小小小朋友 @ 2021-07-26 18:32:16

@209074013钱毅凡

def fact(num):
    sum = 1
    for i in range(1, num + 1):
        sum*=i
    return sum
a = int(input())
for i in range(0, a):
    strnum = input().split(' ')
    d = str(fact(int(strnum[0])))
    sum = 0
    for j in d:
        if int(j) == int(strnum[1]):
            sum += 1
    print(sum)

改成这样就好了


by LoneWolf @ 2021-07-26 18:35:56

sum这个东西是系统关键字,不能用于变量名,建议你用Sun(注意大写)或s


by LanQiDongLai @ 2021-07-26 21:02:41

@小小小朋友 感谢orz


by LanQiDongLai @ 2021-07-26 21:03:02

@Bert_李_MC 学到了


|