這是我的程序來計算GTIN-8數字的第八位數字。追加數字到分割列表
目標是創建一個列表,用戶可以輸入7位數字,將列表拆分成單獨的值,將數字1,3,5,7乘以3並將其添加到其餘列表中。
origSevList = []
def enterDig():
global origSev
origSev = input("Please enter your seven digit number for your GTIN-8 code ")
origSevList.append(origSev)
return origSevList
def splitList(origSevList):
global item
for item in origSevList:
item.split(',')
origSevList = [item[0], item[1], item[2], item[3], item[4], item[5], item[6]]
print (("Inputted seven digits number split in a list"), origSevList)
def xThree(origSevList):
global xByThree
xByThree = int(item[0])*3 + int(item[2])*3 + int(item[4])*3 + int(item[6])*3
def xOne(origSevList):
global xByOne
xByOne = int(item[1]) + int(item[3]) + int(item[5])
def addOneThree(origSevList):
global addSev
addSev = xByThree + xByOne
print (("The sum of your seven digits mulitplied alternately by 1 and 3 ="), addSev)
下一步是找到第8位
def eighthDigit(origSevList):
global eighth
roundNum = ((addSev + 9) // 10*10)
eighth = roundNum - addSev
print (("Your eighth digit is"), roundNum - addSev)
print ((addSev + 9) // 10*10)
enterDig()
splitList(origSevList)
xThree(origSevList)
xOne(origSevList)
addOneThree(origSevList)
eighthDigit(origSevList)
現在我需要做的就是追加第8位到列表中,並打印得到充分GTIN8數。任何想法如何做到這一點?我是一個初學者,請原諒我的亂碼
'final_number = int(origSev)* 10 + int(第八)'。不是嗎? – EbraHim
@EbraHim對不起,我不知道如何把它放在我的代碼中,我會在哪裏放置它?輸入7位數字和分割後的列表如下所示:['1','2','3','4','5','6','8']。我需要它看起來像這樣[1,2,3,4,5,6,8,7] –