Click here to Skip to main content
15,923,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just want to know if there is any way I could nest any of these loops together.
Python
Card_Number = input("Input credit card")
Total = 0

for index in reversed (range ( len ( Card_Number ) ) ):
    Current_Value = int ( Card_Number [index] )

    if index % 2 == 0:
        Current_Digit = Current_Value * 2

        if Current_Digit < 10:
            Total = Total + Current_Digit
        else:
            Total = Total + Current_Digit - 9
    else:
            Total = Total + Current_Value

Valid = ( "This is not a valid credit card number" )
if Total % 10 == 0:
    Valid = ( "This is a valid credit card number" )

Credit_Card_Clear = Card_Number.replace("0", "")
Credit_Type = ""

if Credit_Card_Clear.startswith("34") or Credit_Card_Clear.startswith("37"):
    Credit_Type = "American Express"

elif Credit_Card_Clear.startswith("6011"):
    Credit_Type = "Discover"
    
elif Credit_Card_Clear.startswith("51") or Credit_Card_Clear.startswith("52") or Credit_Card_Clear.startswith("53") or Credit_Card_Clear.startswith("54"):
    Credit_Type = "MasterCard"

elif Credit_Card_Clear.startswith("4"):
    Credit_Type = "VISA"

else:
    Credit_Type = "We do not accept that kind of card"

print(Credit_Type)
print(Valid)


What I have tried:

I just wrote it this way and was wondering if there was any way I could shorten it up.
Posted
Updated 17-Oct-16 17:31pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900