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

this is for PYTHON Write a file named credit_card.py containing a single functio

ID: 3598729 • Letter: T

Question

this is for PYTHON

Write a file named credit_card.py containing a single function, check. Check accepts a single input – a positive integer. It returns True if the integer represents a valid credit card number. As with all functions that return a bool value, if it does not return True it should return False. Credit card numbers have what is called a check digit. This is a simple way of detecting common mis-typings of card numbers. The algorithm is as follows:

1. Form a sum of every other digit, including the right-most digit; so 5490123456789128 (5490123456789128) sums to 4 + 0 + 2 + 4 + 6 + 8 + 1 + 8 = 33.

2. Double each remaining digit, then sum all the digits that creates it; the remaining digits (5 9 1 3 5 7 9 2) in our example (5490123456789128) double to 10 18 2 6 10 14 18 4, which sums to 1+0 + 1+8 + 2 + 6 + 1+0 + 1+4 + 1+8 + 4 = 37

3. Add the two sums above (33 + 37 = 70)

4. If the result is a multiple of 10 (i.e., its last digit is 0) then it was a valid credit card number.

EXAMPLE:

When you run credit card.py, nothing should happen. It defines a function, it does not run it. If in another file (which you do not submit) you write the following: import credit_card if credit_card.check(1) print('ERROR: 1 is not valid") if credit_card.check(240): printC'GOOD: 240 is valid' if credit_card.check(9548): print'G0OD: 9548 is valid' if credit_card.check(5490123456789129): printC'ERROR: 5490123456789129 is not valid') you should get the following output: GOOD: 240 is valid GOOD: 9548 is valid

Explanation / Answer

def check(card):
str_card = str(card)
sumCard = 0
for i in range(1, len(str_card), 2):
sumCard += int(str_card[i])
remaining = ""
for i in range(0, len(str_card), 2):
remaining += str(2*int(str_card[i]))

sum_remaining = 0
for i in range(0, len(remaining)):
sum_remaining += int(remaining[i])

total_sum = sumCard + sum_remaining
return total_sum%10 == 0

Am unable to get how 240 is valid

2 4 0

so sum of every other digit = 4

sum of twice 4 + 0 = 4

there sum is 8

which is not divisble by 10

# code link: https://paste.ee/p/CYyYq

show me how 240 is valid (if you feel it is) and accordingly I will try to make those changes.