Question: Write a Python program that asks for a credit card number (input as a string without hyphens or spaces, not as a number), and reports
Write a Python program that asks for a credit card number (input as a string without hyphens or spaces, not as a number), and reports the card type (American Express, MasterCard, or Visa), and whether the card is valid. So, for the example above (4735672384163216), your program should output 4735672384163216--------VISA: VALID, i.e., the number as a string, 8 hyphens, and VISA: VALID. If the entered number is anything other than a valid CC number, your program should output the number as a string, eight hyphens, and INVALID NUMBER.
def get_card_type (CCNumber): if s[0]=="4": return "VISA" if s[0]=="5": return "MASTERCARD" if s[0]=="3": return "AMERICAN EXPRESS" def isValid (CCNumber): sum=0 dig_number = len(CCNumber) oddeven = num_digits and 1 for count in range (0,num_digits): digit = int(CCNumber[count]) if not ((count and 1)^oddeven): digit = digit*2 if digit > 10: digit = digit - 10 sum = sum + digit return ((sum%10)==0) def main(): m=open("CCNumbers.py","r") CCNumber=int(input()) for i in m: s = i[0:len(i)-1] isValid = (isValid) if isValid == False: print ("---------INVALID CREDIT CARD NUMBER.") else: getcardtype = get_card_type print (s+ getcardtype + ":VALID CREDIT CARD NUMBER") m.close()
What is wrong with my code?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
