I wrote a Python code that is validating Credit Card Numbers. Some of the advanced programmers told me my whole code is messy. How can I make my code cleaner?
#!/usr/bin/python
def CheckNumber(CreditCardNumber) :
#------------------------------------------------------------------#
print("\nYour Credit Card Number is : " , CreditCardNumber , "\n")
#------------------------------------------------------------------#
CreditCardNumber = list(map(int, CreditCardNumber))
x = len(CreditCardNumber) - 2
y = len(CreditCardNumber) - 1
z = 0
WorkingList = []
#------------------------------------------------------------------#
while x >= 0 :
WorkingList.append(CreditCardNumber[x] * 2)
x -= 2
#------------------------------------------------------------------#
while y >= 0 :
WorkingList.append(CreditCardNumber[y])
y -= 2
#------------------------------------------------------------------#
WorkingListStr = list(map(str , WorkingList))
WorkingListStr = "".join(WorkingListStr)
del WorkingList[:]
while z < len(WorkingListStr) :
WorkingList.append(WorkingListStr[z])
z += 1
WorkingList = list(map(int , WorkingList))
#------------------------------------------------------------------#
Mod10 = sum(WorkingList) % 10
#------------------------------------------------------------------#
if Mod10 == 0 :
return True
else :
return False
#---------------------------------------------------------------------------#
CardNumber = input("Credit Card Number : ")
CheckNumberStr = str(CardNumber)
#---------------------------------------------------------------------------#
First4 = CheckNumberStr[0] + CheckNumberStr[1] + CheckNumberStr[2] + CheckNumberStr[3]
First2 = CheckNumberStr[0] + CheckNumberStr[1]
#---------------------------------------------------------------------------#
if len(CheckNumberStr) > 12 and len(CheckNumberStr) < 17 :
# "Visa Card" Checking
if CheckNumberStr[0] == "4" :
CheckBool = CheckNumber(CheckNumberStr)
if CheckBool == True :
print("This is a Valid \" Visa \" Credit Card !")
else :
print("This is not a Valid \" Visa \" Credit Card")
# "MasterCard" Card Checking
if CheckNumberStr[0] == "5" and CheckNumber[1] < "6" and CheckNumber[1] > "0" :
CheckBool = CheckNumber(CheckNumberStr)
if CheckBool == True :
print("This is a Valid \" MasterCard \" Credit Card")
else :
print("This is not a Valid \" MasterCard \" Credit Card")
# "Diners Club Card" Checking
if CheckNumberStr[0] == 3 and CheckNumberStr[1] == 6 or CheckNumberStr[0] == 3 and CheckNumberStr[1] == 8 :
CheckBool = CheckNumber(CheckNumberStr)
if CheckBool == True :
print("This is a Valid \" Diners Club \" Credit Card")
else :
print("This is not a Valid \" Diners Club \" Credit Card")
# "Discover" Card Checking
if First4== "6011" or First2 == "65" :
CheckBool = CheckNumber(CheckNumberStr)
if CheckBool == True :
print("This is a Valid \" Discover \" Credit Card")
else :
print("This is not a Valid \" Discover \" Credit Card")
# "JCB" Card Checking
if First2 == "35" :
CheckBool = CheckNumber(CheckNumberStr)
if CheckBool == True :
print("This is a Valid \" JCB \" Credit Card")
else :
print("This is not a Valid \" JCB \" Credit Card")
# "American Express" Card Checking
if First2 == "34" or First2 == "37" :
CheckBool = CheckNumber(CheckNumberStr)
if CheckBool == True :
print("This is a Valid \" American Express \" Credit Card")
else :
print("This is not a Valid \" American Express \" Credit Card")
#----------------------------------------------------------------------------#
else :
print("Sorry , but this is not a Credit Card Number !")
#----------------------------------------------------------------------------#