Suppose that an automated manufacturing tracker records production QC test results in batches in a results string. For example,
Q2p1d1
would indicate that a single batch of two QC tests was performed with the results of one pass and one defect. Note that the character Q is used to start a batch of QC test results. The character p is to identify the number of tests that passed the QC test, and the character d indicates the number of defects. More than one batch of QC test results can be reported in a single results string. For example,
Q2d1p1Q5p3d2
would indicate two batches of QC test results, one with two test results and one with five test results, with a combined total of four passes and three defects.
Precisely, to be a valid QC test results string,
· a batch of results must begin with the character Q (case sensitive)
· a batch of results must report both pass and defect test results with p and d in either order
· no leading zeros are allowed in any numeric value being reported
· the total number of QC tests in a batch must equal the number of pass and defect test results.
· the total number of QC tests in a batch must be greater than zero XXXXXXXXXXa single result string may include multiple batches of results
All of the following are examples of valid result strings:
· Q1p0d1Q1d0p XXXXXXXXXXtwo batches of results, two total tests, one pass, one defect)
· Q5d2p3 XXXXXXXXXXone batch of results, five total tests, two defects, three passes)
All of the following are examples of invalid result strings:
· q1p0d1 XXXXXXXXXXbatch must be reported with Q) • Q1pd1 XXXXXXXXXXa number for pass is required)
· Q1p1d XXXXXXXXXXa number for defect is required)
· Q1p0d1 asdfR XXXXXXXXXXextra characters not allowed)
· Q5p00003d XXXXXXXXXXleading zeros not allowed)
· Q5p0d0 XXXXXXXXXXpass and defect results must equal the total number of tests)
· Q0p0d0 XXXXXXXXXXbatch cannot be zero)
Your task
For this project, you will implement the following function, using the exact function name, parameter type, and return type shown in this specification. (The parameter and variable names may be different if you wish. Again the function name must be isValidString).
def isString(s):
eturn isNotString
s is the QC test results string (see above examples of valid and invalid test result strings.)
isNotString is a boolean variable that stores either a True or False value.
This function returns true if its parameter s is a well-formed test result string described above, or false otherwise.
You should include an adequate level of comments in your code to help the code reviewer understand your code.
Save your Python program as QCString.py. Your QCString.py should include the isString() function and other supporting functions that you developed and called from the isString() function. Please remove all output statements (print()) from your functions if you used any output statements like print() to help you to test and debug.
IMPORTANT: You can only use Python built-in functions to write this program. You are not allowed to use any imported modules, packages, or li
aries such as pandas, NumPy, math, etc. the goal of this assignment is to practice:
· Program design
· User-defined functions with a return value
· Global variables
· Boolean variables
· Arithmetic operators
· Assignment operators
· Comparison operators
· Logical operators
· If-elif-else control statements including nested ifs.
· While loops
· Data type casting
· String index, built-in string len() and isdigit() functions
You should be able to complete the assignment with the above-mentioned built-in Python features.
Make sure that you test your function with both valid and invalid test result strings. We will be testing your function with 30 test cases (QC test result strings).