Question

Please write code in Python!Check digit 「ロロロロロロロ 27 31 | 心心心心心心心点,可口 口口口口口口口 (a) Computing the check digit. 3 (b) Checksum validation.

You are asked to implement the following checksum formula to validate an identifi- cation 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. Write a function called validateID that takes as input an identification number and returns 1 if the number is a valid checksum, 0 otherwise; it also returns the checksum that is calculated. The identification number is supplied to the function as a string.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code :-

def validateID(idNumber):
   numberList = [int(i) for i in idNumber] #creating list of integers using list comprehension
   checkDigit = numberList.pop()
   total = 0
   flag = 0
   for i in range(len(numberList)):
       if (i%2==0):
           total+=numberList[i]
       else:
           temp = numberList[i]*2
           if (temp>9):
               total+=1 #add the 1 from ten's place
               temp%=10 #obtain one's place digit
           total+=temp
       #print(total) --used for checking
      
   total+=checkDigit #add the checkDigit value
   if (total%10==0): #if divisible by 10 then valid
       flag = 1
   return total,flag

def main():
   identificationNumber = "1762483"
   total,flag = validateID(identificationNumber)
   if (flag):
       print("Valid data : Total is ",total)
   else:
       print("Invalid data : Total is ",total)

#checks if file was run as script or imported
if __name__ == '__main__': main()

Output :-

Valid data : Total is 30

Add a comment
Know the answer?
Add Answer to:
Please write code in Python! You are asked to implement the following checksum formula to validate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in Python that asks the user for the ISBN of the book in...

    Write a program in Python that asks the user for the ISBN of the book in the format xxx-x-xxx-xxxxx-x. To validate: Initialize a total to 0 Have the program remove the dashes so that only the 13 digits are left in the ISBN string for each index of the first 12 digits in the 13 digit ISBN string get the digit at the current index as an integer If the current index is an even number, add the digit to...

  • Write in java . I started it can you finish it. I will rate if code...

    Write in java . I started it can you finish it. I will rate if code works What is this lab about and what will you be working on? In this lab, you will practice new tools and concepts you've learned in class and in lab. Namely this lab will be on methods, arrays (1D and 2D), and on repetition (using loops) In this lab, you will have to complete two activities. Here is what you have to do: Activity...

  • Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program...

    Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program that works as described in the following scenario: The user enters a credit card number. The program displays whether the credit card number is valid or invalid. Here are two sample runs: Enter a credit card number as a long integer: 4388576018410707 4388576018410707 is valid Enter a credit card number as a long integer: 4388576018402626 4388576018402626 is invalid To check the validity of the...

  • Instructions Good news! You have are nearly finished with the semester! Today’s problem is going to...

    Instructions Good news! You have are nearly finished with the semester! Today’s problem is going to be to modify a program to match the actual check used to verify Social Insurance Numbers. Don’t worry, the first part of the solution has been taken care of for you. You just need to modify it to also check the bits in BOLD font. A valid SIN is calculated by multiply odd-positioned digits (1st, 3rd, 5th, 7th, & 9th) by 1 and even-positioned...

  • Instructions In this problem, you will update the declaration for a function called validateSIN (), using...

    Instructions In this problem, you will update the declaration for a function called validateSIN (), using the@paran and @re turn COmments and write the appropriate code for the function to check if a given SIN is valid or not You can test to see if a SIN is valid by using the following calculation. (WARNING: While this Is similiar to the ISBN validation calculation, It Is not the same. There are several differences] Remove hyphens so just digits remain ultiply...

  • PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program tha...

    PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program that reads a values for hour and minute from the input test file timeData.txt . The data read for valid hour and valid minute entries. Assume you are working with a 24 hour time format. Your program should use functions called validateHour and validateMinutes. Below is a sample of the format to use for your output file  timeValidation.txt :   ...

  • Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit...

    Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit card number and determines whether it is valid or not. (Much of this assignment is taken from exercise 6.31 in the book) Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits, and must start with: 4 for Visa cards 5 for Master cards 6 for Discover cards 37 for American Express cards The algorithm for determining...

  • Modify current code to complete the following: Current code: Validate a Web IP address which will...

    Modify current code to complete the following: Current code: Validate a Web IP address which will accept the following positive examples: 1.1.1.1 192.0.0.255 255.255.255.255 The IP address comprises four parts each of which is one to three digits, with each part separated by a DOT or period. To match a single digit, or two digits, or three digits, you will need to use the curly braces to specify the minimum and maximum number of digits desired. digits, you will need...

  • USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by...

    USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by the user. Remember that x! =x* (x-1)* (x-2)*... *3+ 2* 1. Your program should check the value input by the user to ensure it is valid (i.e., that it is a number > =1). To do this, consider looking at the is digit() function available in Python. If the user enters an incorrect input, your program should continue to ask them to enter a...

  • Write the code in PYTHON and please provide the full code, thank you! Write a program...

    Write the code in PYTHON and please provide the full code, thank you! Write a program that plots two functions: f(x) = x2 and g(x) = ax. Write it in such a way that the intersection points are marked with an X, for arbitrary a. • You may use your favorite ready-made function to find the intersection points, if not: • One possible way to tackle this problem is to put both function values in arrays and check using a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT