AKkkk_TIX @ 2024-07-25 14:24:48
s = input()
last = s[-1]
s = s[:-2]
num = 0
total = 0
for i in s:
if i != '-':
num += 1
cal = int(i) * num
total += cal
mod = total % 11
if mod == last:
print("Right")
else:
print(f"{s}-{mod}")
记录详情
by qiuby123456 @ 2024-07-25 14:30:20
如果余数为
mod
by qiuby123456 @ 2024-07-25 14:30:38
@a_programmer
by qiuby123456 @ 2024-07-25 14:37:22
还有在第14、15行之间插入如下代码的时候:
print(type(mod), type(last), type(mod)==type(last))
会输出
<class 'int'> <class 'str'> False
所以建议倒数第四行改为:
if mod == 10 and last == 'X' or str(mod) == last:#这里不使用mod==int(last)的原因是last可能等于'X'