Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Credt card number validation Program Credit card numbers follow certain patterns

ID: 3706471 • Letter: C

Question

Credt card number validation Program Credit card numbers follow certain patterns: It must have between 13 and 16 digits, and the number must start 4 for Visa cards 5 for MasterCard credit 37 for American Express cands 6 for Discover cands In 1954, Hans Luhn of IBM proposed an algorithm for validating credit cand numbers. The algorithm is useful to determine whether a card number entered correcty or whether acredit card is scanned comedy by a scanner. Credt card numbers are generated following this validny check, commonly known as the Luhn check o the Mod 1O check, which can be descibed as follows (for ustration, consider the card number 388576018402828) 1. Double every second digit from right to left. H doubling of a digit resuits in a two-digit number, add up the two digts to get a singie-digit number 2-12 (1-2-3 2-16 16 2 Now add al singie-digit numbers from Step 1 4+4+8+2+3+1+7+8137 Add all digits in the odd places from right to left in the cand number +6 0+8+0 7 83 38 4. Sum the resuits from Steps 2 and 3 5. If the result from Step 4 is divisible by 10, the card number is valid, otherwise, it is invald. For example, the number 4388576018402626s iaid, but the number 4388576018410707 is valid Write a program hat prompts the user to enter a credit card number as a STRING Allow the user to check muliple credit numbers until user decides to quit. Prompt the user for how many credt card numbers helshe wants to check. You are to use the two credit card numbers provided in the sample output given below plus other credt card numbers using credit numbers that starts with 5, 37 and 6. Make sure you test at least 10 credt card numbers Display whether the number is valid or invalid. Design your progam to use the foilowing functions (include type annotations def mainO Buser will input the credit cand number as a sting ocall the tunction isValid) and print whether the credt card number is valid or not vald Retum true i he card number is Get the eut fom Step 2 #thosum oftho two diges Rstum sum of odd place digits in umber Here are te two sample runs using the credt cand numbers above

Explanation / Answer

def main():
n=input("How many credit numbers you want to check? (You can quit any time by typing Quit ")
for i in range(0,int(n)):
credit=input("Enter a credit card number as long integer:")
if(credit=="Quit"):
break
else:
credit=int(credit)
if(isValid(credit)==True):
print(credit, "is Valid")
else:
print(credit, "is invalid")
  
#user
def isValid(number):
even=sumOfDoubleEvenPlace(number)
odd=sumOfOddPlace(number)
#print(odd+even)
if((even+odd)%10==0):
return True
else:
return False
#here
def sumOfDoubleEvenPlace(number):
sum1=0
counter=1
for digits in reversed(str(number)):
if(counter%2==0):
#print("even",digits)
temp=int(digits)*2
sum1+=getDigit(temp)
counter+=1
#print(sum1)
return sum1   
#here
def getDigit(number):
if(len(str(number))>1):
temp_sum=int(str(number)[0])+int(str(number)[1])
return temp_sum
else:
return number
  
#here
def sumOfOddPlace(number):
sum1=0
counter=1
for digits in reversed(str(number)):
if(counter%2!=0):
#print("odd",digits)
sum1+=int(digits)
counter+=1
#print(sum1)
return sum1

main()

"""
test cases:
4388576018410707 - valid
4388576018402626 - Invalid
4386576028010707 - Invalid
4386576028012626 - Invalid
5388576018410707 - invalid
5388576018402626 - invalid
3788576018410707 - invalid
3788576018402626 - invalid
6388576018410707 - invalid
6388576018402626 - Valid

"""

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote