python求助

P1055 [NOIP2008 普及组] ISBN 号码

Dr_Roy @ 2024-04-23 12:02:40

为什么第一个数据点会WA,改了isbn[-1]为eval(isbn[-1])又变成2和9RE```python

判断书本识别码

isbn_old=input() isbn=isbn_old.replace("-","") he=0 yinshu=0 for i in range(0,len(isbn)-1): yinshu+=1 he+=int(isbn[i])*yinshu testcode=int(he%11) if testcode==10: if isbn[-1]=="X": print("Right") else: print(isbn[0],end="") print("-",end="") print(isbn[1:4],end="") print("-",end="") print(isbn[4:9],end="") print("-X",end="") else: if isbn[-1]=="X": print(isbn[0],end="") print("-",end="") print(isbn[1:4],end="") print("-",end="") print(isbn[4:9],end="") print("-",end="") print(testcode) else: if isbn[-1]==testcode: print("Right") else: print(isbn[0],end="") print("-",end="") print(isbn[1:4],end="") print("-",end="") print(isbn[4:9],end="") print("-",end="") print(testcode)


|