Currygirl63 - 7 months ago 52
Python Question

# int() argument must be a string or a number, not 'tuple'

This is my coding:

``````#Getting them to import their code:
number = int(input("Enter 7 digit GTIN code to get eighth number : "))

#importing math for subtracting later:
import math

#Getting the numbers X3 & X1 and then adding them:
def eight(total):
multiplier = [3, 1]
total = 0
for i, digit in enumerate(str(number)):
total = total + int(digit)*multiplier[i%2]

#Subtracting the total to get the last number:
nearest_10 = int(math.ceil(total / 10.0)) * 10
return nearest_10 - total

code = number,eight(number)
code = int(code)
print(code)

#printing their full number:

#Checking the validity of the eight digit GTIN-8 code:

def validity(valid):
multiplier = [3, 1]
valid = 0
string = ""
for i, digit in enumerate(list(str(code))):
valid = valid + str(digit)*multiplier[i%2]
string = string+str(str(digit)*multiplier[i%2])+", "

if code % 10 == 0:
print"Valid"
else:
print"Not valid"
``````

However when I am trying to convert my code to an integer for later, as it needs to be a single integer for the answer, it says this:

``````code = int(code)
TypeError: int()
argument must be a string or a number, not 'tuple'
``````

Answer

Easy way to fix this is to concatenate the numbers as a string and do an int() on the resulting string . Something like :

``````code = '%s%s' % (number,eight(number))
code = int(code)
print(code)
``````