I have created a code with the help of a few user on stackoverflow. I have found a problem in my code. The problem with my code is that when the user enters the ISBN wrong more than twice then it code up with an error
here's my code:
isbn= input('Please enter the 10 digit number: ')
while not(len(isbn) == 10 and isbn.isdigit()):
print('Please make sure you have entered a number which is exactly 10 characters long.')
isbn=input('Please enter the 10 digit number: '))
continue
else:
total= 0
for digit in isbn: total += int(digit)
calculation=total%11
digit11=11-calculation
if digit11==10:
digit11='X'
iSBNNumber=str(isbn)+str(digit11)
print('Your 11 digit ISBN Number is ' + iSBNNumber)
In a while
loop, the following code tries to convert the input string to int
.
isbn = int(input('Please enter the 10 digit number: '))
int
objects has no isdigit
methods; cause AttributeError
.
>>> isbn = 12345
>>> isbn.isdigit()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'isdigit'
len(int)
causes TypeError
.
>>> len(isbn)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'int' has no len()
Remove int(..)
call.
isbn = input('Please enter the 10 digit number: ')