I've been trying to work out ways to define check_sum for the execution of this bool function. The error message that has been showing on my screen is "NameError: name 'check sum' is not defined. Could anyone please help me with correcting this error? Thank you very much :-)

  • My code would look hideously wrong to what I rightly believe would be many people..I am completely new to programming or coding whatsoever so any notes or advice would be more than welcome!!


def main():

Card_number = int(input("Credit card number:          "))
while len(Card_number) >= 13 and check_sum:
    Card_number_string = str(Card_number)
    first_digit = Card_number_string[:1]
    two_digits = Card_number_string[:2]

    if(first_digit == 4):
        if(two_digits == 34 or 37):
            if(two_digits == 51 or 52 or 53 or 54 or 55):

bool (check_sum)

Validating credit card number

while len(Card_number) >= 13: Card_number = "Copy"

#Extracting every digit
for digits in range(Copy):
    digits = int (digits %d)
    # Multiplying second digits by two
    Second_digits = int (Copy % 10) * 2
    #Adding the numbers
    sum += Copy % 10
    Copy /= 10

if sum % 10 == 0:


1 Answer 1


Syntax error. Your code is:

bool (check_sum)

If it's a function, it should look like this:

def check_sum():

And, of course, the code for check_sum follows with the appropriate indent.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Thank you so much for your clear-cut response! :-) And, of course! It's the least I can do for your help, thank you.
    – Jae-Min
    Commented Jan 21, 2023 at 16:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .