Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

C++ Implement a dictionary by using hashing and separate chaining.

Answered: 1 week ago