python 四个RE 有没有大佬帮我看看

P1055 [NOIP2008 普及组] ISBN 号码

sean_code @ 2022-06-01 09:58:09

a, b, c, d = map(str, input().split('-'))
x = a+b+c
Sum = 0
for i in range(len(x)):
    Sum = Sum + int(x[i])*(i+1)
if Sum % 11 == int(d):
    print('Right')
elif Sum % 11 < 10:
    print(f'{a}-{b}-{c}-{Sum%11}')
elif Sum % 11 == 10:
    print(f'{a}-{b}-{c}-X')

by Terrible @ 2022-06-01 10:22:07

考虑输入数据最后一位是 'X',而且在洛谷建议输入字符串数据的时候顺手 .strip()以筛掉 \r(回车符),也就是 input().strip()(但是要注意它同时会筛掉空格等)

a, b, c, d = map(str, input().strip().split('-'))
x = a+b+c
Sum = 0
for i in range(len(x)):
    Sum = Sum + int(x[i])*(i+1)
if d == 'X' and Sum % 11 == 10 or d !='X' and Sum %11 == int(d):
    print('Right')
elif Sum % 11 < 10:
    print(f'{a}-{b}-{c}-{Sum%11}')
elif Sum % 11 == 10:
    print(f'{a}-{b}-{c}-X')

by sean_code @ 2022-06-01 13:44:34

@Terrible 我悟了,谢谢佬


|