我似乎无法确保 python 模函数正常工作,我尝试了各种数字,但似乎无法得到正确的除法。
国际标准书号
print """
Welcome to the ISBN checker,
To use this program you will enter a 10 digit number to be converted to an International Standard Book Number
"""
ISBNNo = raw_input("please enter a ten digit number of choice")
counter = 11 #Set the counter to 11 as we multiply by 11 first
acc = 0 #Set the accumulator to 0
开始循环,将字符串中的每个数字乘以递减计数器我们需要将数字视为字符串以获得每个位置
for i in ISBNNo:
print str(i) + " * " + str(counter)
acc = acc + (int(i) * counter) #cast value a integer and multiply by counter
counter -= 1 #decrement counter
print "Total = " + str(acc)
Mod除以11(除以余数
acc = acc % 11
print "Mod by 11 = " + str(acc)
从 11 开始
acc = 11 - acc
print "subtract the remainder from 9 = " + str(acc)
与字符串连接
ISBNNo = ISBNNo + str(acc)
print "ISBN Number including check digit is: " + ISBNNo