python ,全是RE,帮忙看一下为什么(请你喝奶茶?)

P1055 [NOIP2008 普及组] ISBN 号码

cailiao1234 @ 2023-06-02 22:40:18

代码如下:

d_number = input().replace('-', '')
digits = [int(d) for d in id_number[:-1]]
checksum = sum([(i+1)*d for i, d in enumerate(digits)]) % 11
if checksum == 10:
    checksum = 'X'
if str(checksum) == id_number[-1]:
    print('Right')
else:
    print('{0}-{1}{2}{3}-{4}{5}{6}{7}{8}-{9}'.format(*id_number[:-1], checksum))

by ___Yang__ @ 2023-06-02 22:47:35

@cailiao1234

AC代码

id_number = input().replace('-', '')//这里的 id_number 变量名错了
digits = [int(d) for d in id_number[:-1]]
checksum = sum([(i+1)*d for i, d in enumerate(digits)]) % 11
if checksum == 10:
    checksum = 'X'
if str(checksum) == id_number[-1]:
    print('Right')
else:
    print('{0}-{1}{2}{3}-{4}{5}{6}{7}{8}-{9}'.format(*id_number[:-1], checksum))

by cailiao1234 @ 2023-06-02 23:00:15

@Yangbowen0108 从pycharm复制过来,居然掉了一个i。 十分感谢!!!


by ___Yang__ @ 2023-06-03 07:50:58

@cailiao1234 不客气


|