Question: Write a program (q4.py) that generates random barcode numbers and uses the function from the previous question to validate them. The program will request an

Write a program (q4.py) that generates random barcode numbers and uses the function from the previous question to validate them. The program will request an integer number n from the user. The program will continue running until n valid barcode numbers have been randomly generated. Barcode numbers are made up of 13 numerical digits. When the program terminates it will display the number of non-valid barcode numbers that were generated in the simulation and the ratio between valid and invalid barcode numbers. The function called checkBarcode() checks if a barcode number is valid or not. The checkBarcode() function takes a 13-digit number as a parameter. As a programming exercise, this function requires the use of a looping mechanism to iterate over the digits of the number provided as its parameter. The purpose of this function is to determine if the provided number is a valid barcode number or not.

Here are the steps of the algorithm you need to use: a) Remove the last digit from the sequence. We will refer to this digit as the Check Digit. b) Triple every second digit from left to right and leave the rest of the digits unchanged. c) Sum all the 12 digits from step (b). d) Compute the remainder of sum obtained in step(c) divided by 10. Subtract the remainder from 10. e) If the number obtained in step (d) is equal to the Check Digit then the barcode number is valid. Otherwise, the barcode number is not valid.

Write a program (q4.py) that generates random barcode numbers and uses the

this has to be done python

Below is a sample execution of the program you will write (in this case n 1000): 1Number of valid barcode numbers to generate: 1000 2Results .." 3 Invalid barcode numbers generated 11617 41 Valid / Invalid Ratio: 1000 / 11617 = 0.08608074373762589 Here is another sample execution of the program for part b. In this case n = 30 1Number of valid barcode numbers to generate:30 2Results* 3Invalid barcode numbers generated: 343 411 Valid / Invalid Ratio: 30 / 343 = 0.08746355685131195

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!