[python] TypeError: object of type 'int' has no len() error assistance needed

I am writing a piece of code for my code that when the user inputs 7 digits it multiplies the digits by 3 and 1 respectively. Here is the code;

enter image description here

When it goes to check if the user has entered 7 digits it gives me this error: TypeError: object of type 'int' has no len()

This question is related to python

The answer is


Well, maybe an int does not posses the len attribute in Python like your error suggests?

Try:

len(str(numbers))

Abstract:

The reason why you are getting this error message is because you are trying to call a method on an int type of a variable. This would work if would have called len() function on a list type of a variable. Let's examin the two cases:

Fail:

num = 10

print(len(num))

The above will produce an error similar to yours due to calling len() function on an int type of a variable;

Success:

data = [0, 4, 8, 9, 12]

print(len(data))

The above will work since you are calling a function on a list type of a variable;


May be it is the problem of using len() for an integer value. does not posses the len attribute in Python.

Error as:I will give u an example:

number= 1
print(len(num))

Instead of use ths,

data = [1,2,3,4]
print(len(data))