Question

Program Set 2 10 points) Credit card number validation Program Credit card numbers follow certain patterns: It must have betw

def main() #user wil input the credit card number as a string #call the function isValid() and print whether the credit card

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def getDigit(n):
    n=str(n)
    if len(n)==2:
        n1=int(n[0])+int(n[1])
        return int(n1)
    else:
        return int(n)
def sumOfDoubleEvenPlace(leven):
    sum1=0
    for i in leven:
        x=int(i)
        sum1=sum1+getDigit(2*x)
    return sum1
def sumOfOddPlace(lodd):
    sum2=0
    for i in lodd:
        sum2=sum2+int(i)
    return sum2
def isvalid(number):
    lodd=number[::-2]
    leven=number[len(number)-2::-2]
    result=sumOfDoubleEvenPlace(leven)+sumOfOddPlace(lodd)
    if result%10==0:
        return True
    else:
        return False
def main():
    t=int(input("How many credit card numbers do you want to check?"))
    while t>0:
        number=input("Enter a credid card number as a long integer")
        if isvalid(number)==True:
            print(number+" is valid")
        else:
            print(number+" is invalid")
        t=t-1
main()
Add a comment
Know the answer?
Add Answer to:
Program Set 2 10 points) Credit card number validation Program Credit card numbers follow certain patterns:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Credit card numbers follow certain patterns. A credit card number must have between 13 and 16...

    Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits. The number must start with the following: 4 for Visa cards 5 for MasterCard cards 37 for American Express cards 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or is scanned correctly by a scanner. Almost all credit card numbers...

  • Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit...

    Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit card number and determines whether it is valid or not. (Much of this assignment is taken from exercise 6.31 in the book) Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits, and must start with: 4 for Visa cards 5 for Master cards 6 for Discover cards 37 for American Express cards The algorithm for determining...

  • Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program...

    Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program that works as described in the following scenario: The user enters a credit card number. The program displays whether the credit card number is valid or invalid. Here are two sample runs: Enter a credit card number as a long integer: 4388576018410707 4388576018410707 is valid Enter a credit card number as a long integer: 4388576018402626 4388576018402626 is invalid To check the validity of the...

  • Credit card numbers adhere to certain constraints. First, a valid credit card number must have between...

    Credit card numbers adhere to certain constraints. First, a valid credit card number must have between 13 and 16 digits. Second, it must start with one of a fixed number of valid prefixes : 1 • 4 for Visa • 5 for MasterCard • 37 for American Express • 6 for Discover cards In 1954, Hans Peter Luhn of IBM proposed a “checksum” algorithm for validating credit card numbers . 2 The algorithm is useful to determine whether a card...

  • Banks issue credit cards with 16 digit numbers. If you've never thought about it before you...

    Banks issue credit cards with 16 digit numbers. If you've never thought about it before you may not realize it, but there are specific rules for what those numbers can be. For example, the first few digits of the number tell you what kind of card it is - all Visa cards start with 4, MasterCard numbers start with 51 through 55, American Express starts with 34 or 37, etc. Automated systems can use this number to tell which company...

  • Consider the following credit card numbers and tell me if they are valid or not. If...

    Consider the following credit card numbers and tell me if they are valid or not. If a number is invalid, write the valid credit number by changing the “check” digit. Show your work for full marks. a. 4634 5163 4122 7983 b. 5321 4142 6379 4771 c. How many valid (according to the Luhn check) 16-digit credit card numbers are there that start with these 14 digits 4444 4444 4444 44? Give one of the valid credit card numbers.

  • I want it in C++ 4. When choice 4 (Verify Your Credit Card) is selected, the...

    I want it in C++ 4. When choice 4 (Verify Your Credit Card) is selected, the program should read your credit card (for example: 5278576018410787) and verify whether it is valid or not. In addition, the program must display the type (i.e. name of the company that produced the card). Each credit card must start with a specific digit (starting digit: 1st digit from left to ight), which also is used to detemine the card type according Table 1. Table...

  • The Language is for Java ------ Input ------- credit-cards-2.dat //////////////////// Output//////////// Enter a filename\n Credit card...

    The Language is for Java ------ Input ------- credit-cards-2.dat //////////////////// Output//////////// Enter a filename\n Credit card number: 3056 9309 0259 04\n Checksum: 50\n Card status: VALID\n Credit card number: 3852 0000 0232 37\n Checksum: 40\n Card status: VALID\n Credit card number: 6011 1111 1111 1117\n Checksum: 30\n Card status: VALID\n Credit card number: 6011 0009 9013 9424\n Checksum: 50\n Card status: VALID\n Credit card number: 3530 1113 3330 0000\n Checksum: 40\n Card status: VALID\n Credit card number: 3566 0020 2036...

  • 2.Consider the following credit card numbers and tell me if they are valid or not. If...

    2.Consider the following credit card numbers and tell me if they are valid or not. If a number is invalid, write the valid credit number by changing the “check” digit. Show your work for full marks. a. 4519 6731 6055 4166 b. 4515 1663 4722 3333 c. How many valid (according to the Luhn check) 16-digit credit card numbers are there that start with these 14 digits 4444 4444 4444 45? Give one of the valid credit card numbers. 3....

  • How many valid 16-digit credit card numbers are there that start with these 14 digits 4444...

    How many valid 16-digit credit card numbers are there that start with these 14 digits 4444 4444 4444 45 (according to the Luhn check)? Give one of the valid credit card numbers.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT