我似乎無法確定python的模數函數是否正常工作,我嘗試了各種數字,似乎無法得到正確的分割。Modulo沒有正確處理
ISBN號碼
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
開始循環,由decrimenting計數器 乘以每個字符串中的數字,我們需要把數字作爲一個字符串通過獲得每個位置
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)
國防部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
可以比你更具體的比你沒有得到「正確的劃分」嗎?結果是什麼?你期待什麼? – vossad01 2013-04-21 17:18:19
我期待它除以11,然後減去餘數,例如11。 89將離開我們8和最終數字10從11 – userwill 2013-04-21 17:25:32