Submit your program using the zyBooks system by March 15, 2020, 11:59 pm. Please submit original work. Implement the following checksum formula to validate an identification number given to you. The formula works as follows. Using the original number, double the value of every other digit. Then add the values of the individual digits together (if a doubled value now has two digits, add the digits individually). The identification number is valid if the resulting sum is divisible by 10.

Respuesta :

Answer:

def validateID(this_id):

  is_valid = 0

  checksum = 0

  n = int(this_id)

  count=1

  while(n!=0):

      d=int(n%10)      

      if(count%2==0):

          d=d*2

          if(d<10):          

              checksum=checksum+d

          else:

              while(d!=0):

                  x = int(d%10)

                  checksum = checksum + x

                  d=int(d/10)

      else:      

          checksum=checksum+d

      count=count+1

      n=int(n/10)

  if(checksum%10==0):

      is_valid=1

  return is_valid, checksum

def main():

  test_id = "176248"

  is_valid, checksum = validateID(test_id)

  if(is_valid==1):

      print(test_id+" is valid and checksum is "+str(checksum))

  else:

      print(test_id+" is not valid and checksum is "+str(checksum))

  test_id = "79927398713"

  is_valid, checksum = validateID(test_id)

  if(is_valid==1):

      print(test_id+" is valid and checksum is "+str(checksum))

  else:

      print(test_id+" is not valid and checksum is "+str(checksum))

  test_id = "6080320539447211"

  is_valid, checksum = validateID(test_id)

  if(is_valid==1):

      print(test_id+" is valid and checksum is "+str(checksum))

  else:

      print(test_id+" is not valid and checksum is "+str(checksum))

  return

if __name__ == '__main__':

  main()