你好,我想问一下字符串和整数的转换问题。
我有一个块代码,需要字符串和整数之间的转换,但我只是不能让它工作,我想知道是否有人可以帮助我。I receive String index out of range
error.
代码
def ISBN(bc):
total = 0
up = 0
down = 11
for x in range(10):
sbc = str(bc)
ibc = int(sbc[up])
total += (ibc * down)
#total += (int(sbc[up])*down)
up += 1
down -+ 1
mod = (total % 12)
if mod == 10:
total = "x"
print ("The ISBN book code is: " + bc + total)
w = 0
while w == 0:
a = int(input("Please input the 10 digit book number:n"))
b = str(a)
if len(b) == 9:
ISBN(a)
else:
print ("Sorry book code not 10 digits long")
restart = input("Would you like to use the book code changer again?n")
restart = restart.lower
if restart == "yes" or restart == "y":
print ("--------------------------------------------------n")
elif restart == "no" or restart == "n":
print ("Thank you for using the ISBN book code changern")
w = 1
if len(b) == 9:
应该是10。
mod = (total % 12)
应该是11