I'm working on a small script to check credit cards and bank validity but for a crazy reason I get an error I do not understand.
#!/usr/bin/python
# -*- coding: utf-8 -*-
def digitSum(myString):
length = len(myString)
oddSum = 0
evenSum = 0
#base case
if (length ==0):
return 0
#length > 0
else:
#if even
if (length % 2 ==0):
last = int(myString[-1])
evenSum += last
return evenSum + digitSum(myString[:-1])
else:
last = int(myString[-1])
last = 2 * last
part_sum = last // 10 + last % 10
oddSum += part_sum
return oddSum + digitSum(myString[:-1])
def luhns():
myString = input("Entrez les 16 numéros de la Carte de Crédit ")
total = digitSum(myString)
if (total % 10 == 0):
if total[:1] == "4":
cardtype = "Visa"
if int(total[:2]) >= 51 and int(total[:2]) <= 55:
cardtype = "Master Card"
if total[:2] == "34" or total[:2] == "37":
cardtype = "American Express"
if total[:4] == "6011":
cardtype = "Discover"
if total[:2] == "36":
cardtype = "DINERS"
if int(total[:3]) >= 300 and int(total[:3]) <= 305:
cardtype = "DINERS"
return cardtype
print ('Carte valide') + cardtype
else:
print ('Carte invalide')
def main():
luhns()
#Python call to main()
main()
This is the error I'm getting:
Entrez les 16 numéros de la Carte de Crédit 11111
Traceback (most recent call last):
File "/Volumes/Python/LuhnsAlgorithm.py", line 61, in <module>
main()
File "/Volumes/Python/LuhnsAlgorithm.py", line 58, in main
luhns()
File "/Volumes/Python/LuhnsAlgorithm.py", line 34, in luhns
total = digitSum(myString)
File "/Volumes/Python/LuhnsAlgorithm.py", line 5, in digitSum
length = len(myString)
TypeError: object of type 'int' has no len()
logout