Computer Science, asked by pacrat4939, 10 hours ago

SanjayDisale06SanjayDisale0631.01.2021Computer ScienceSecondary SchoolansweredThe Torris County Visa Center generates thetoken number for its applicants from theirapplication ID. The application ID is a numericvalue. The token number is generated in aspecific form. The even digits in the applicant'sID are replaced by the digit one greater thanthe even digit and the odd digits in theapplicant's ID are replaced by the digit onelesser than the odd digit. The numeric valuethus generated represents the token numberof the applicant. write an algorithm to generate the token number from the applicant id​

Answers

Answered by ftrahulpal
1

Answer:

SanjayDisale06SanjayDisale0631.01.2021Computer ScienceSecondary SchoolansweredThe Torris County Visa Center generates thetoken number for its applicants from theirapplication ID. The application ID is a numericvalue. The token number is generated in aspecific form. The even digits in the applicant'sID are replaced by the digit one greater thanthe even digit and the odd digits in theapplicant's ID are replaced by the digit onelesser than the odd digit. The numeric valuethus generated represents the token numberof the applicant. write an algorithm to generate the token number from the applicant

Answered by aljiyashibu
1

Explanation:

The problem states that you must take every other digit, starting with the second-to-last digit. But as you've discovered, this is not the same as simply taking the odd and even digits of the number, since it will give different results for numbers with odd or even lengths. The solution is to reverse the number first, and then take its odd and even digits:

# reverse the digits

cc_reversed = credit_card[::-1]

print(cc_reversed)

# convert to integers

even = [int(i) for i in cc_reversed[1::2]]

odd = [int(i) for i in cc_reversed[::2]]

print(even)

print(odd)

For 4003600000000014 (VISA), this prints:

4100000000063004

[1, 0, 0, 0, 0, 6, 0, 4]

[4, 0, 0, 0, 0, 0, 3, 0]

and for 378282246310005 (AMEX), it prints:

500013642282873

[0, 0, 3, 4, 2, 2, 7]

[5, 0, 1, 6, 2, 8, 8, 3]

So now the list of even digits will always start with the penultimate digit of the original number (i.e. 1 for VISA and 0 for AMEX in the above examples).

UPDATE:

To clarify, here's a simpler example:

>>> '0010'[::2] # even digits

'01'

>>> '0010'[::2][::-1] # even digits, reversed

'10'

For even-length numbers, taking the even digits will always end on the second to last digit (which is what we want). But this will never work for odd-length numbers, because that will always end on the last digit:

>>> '00010'[::2] # even digits

'000'

What we need to do instead is take every other digit starting from the second to last digit. This can be guaranteed by reversing the number first:

>>> '0010'[::-1] # reversed

'0100'

>>> '0010'[::-1][1::2] # reversed, every other digit

'10'

>>> '00010'[::-1] # reversed

'01000'

>>> '00010'[::-1][1::2] # reversed, every other digit

'10'

It's actually misleading to talk about odd and even digits. What really matters is making sure you always start from the same place.

mark me as brain list, please

Similar questions