Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

More Books

Students also viewed these Databases questions

Question

=+Trainers from headquarters? Local trainers? Independent trainers?

Answered: 1 week ago