I am doing some projects so I can teach myself programming. The one that I finished states: "Credit Card Validator - Takes in a credit card number from a common credit card vendor and validates it to make sure that it is a valid number (look into how credit cards use a checksum)." Would be glad if i can get a constructive feedback on this one.
import sys cardnumb_input = input('Enter your credit card number: ') def list_tweak(): try: cardnumb = [int(i) for i in cardnumb_input] cardnumb[0::2] = [x * 2 for x in cardnumb[0::2]] cardnumb = [str(i) for i in cardnumb] cardnumb = list(''.join(cardnumb)) cardnumb = [int(i) for i in cardnumb] return cardnumb except ValueError: print('Please enter only number in format: xxxxxxxxxxxxxxxx') sys.exit(1) def valid_or_not(): total = sum(list_tweak()) if total % 10 != 0: print('It seems that this credit card number is not valid.') else: print('This credit card number is valid. ') valid_or_not()