Question: Can someone help me figure out what I'm doing wrong? The program is supposed to: 1. Accepts as input a text file named card_data.txt which

Can someone help me figure out what I'm doing wrong?

The program is supposed to:

1. Accepts as input a text file named card_data.txt which contains several fictitious sixteen-digit credit card numbers as individual records, validates each record as a sixteen-digit number for length, 2. uses Luhns Algorithm to determine if the number in each record is a valid sixteen-digit credit card number

Code

# Open file card_data.txt

file = open('card_data.txt', 'r')

# Read each line in file and strip

card_num = file.readline().strip()

card_num = int(card_num)

# Close the file

file.close()

# Check card length

def card_len():

index = 0

while card_num != '':

if card_num != 16:

print('This is not a valid card.')

else:

print('This card is a valid.')

index += 1

return card_num

# Check card_num follows alogrithim

def card_check():

length = len(card_num)

odd_sum = 0

even_sum = 0

if (length ==0):

return 0

else:

if(length % 2 == 0):

last = card_nun[-1]

even_sum += last

return even_sum + length

def main():

card_len()

card_check()

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!