Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Answer question 2b only using python. please do not include 2c which is provided here. This is the whole question up to 2b 2a) def
Answer question 2b only using python. please do not include 2c which is provided here. This is the whole question up to 2b
2a)
def getPartsInCode(s):
#initializing the last character to the first one
#and count to zero
last = s[0];count = 0
#iterating over the string and keep the Count
for curr in s:
if curr == last:
count += 1
else:
print(f'{last}{count}',end = " ")
#reset the values of last and count
last = curr
count = 1
print(f'{last}{count}')
s = input("Please enter the string ")
getPartsInCode(s)
Question 2 A factory makes products using parts that are identified by letters A to L. Each product is made of at least 3 different parts, and is identified by a product code made up of letters identifying the parts. The letters in a product code is sorted alphabetically. E.g., a product with product code ABBBG is made up of 1 A, 3 B and 1 G parts. (a) Write and develop a function getPartsInCode which has one string parameter: productCode. The function returns a string in this format: nipi n2p2 ... nkpk. Note nipis are separated by space. For example, if product code is ABBBG, then the function returns 1A 3B 16. Note that the letters in the string parameter are in uppercase and are already sorted. You can use collections of only str type for function. This means collection types such as set, list, dict are not allowed. (5 marks) Apply and employ structured programming and write an application to manage the factory. Other than the data specified in Q2(b), you may use collections of any types for other data in your application. However, you should assume that the user input for product code is not sorted alphabetically. (6) Initialise the following program data in your main method (that is, these variables are not global variables): The stock level for each part is 100 at the start of the application. startLevel = 100 The reorder point for each part is 20. Once the stock level is 20 or below, the part should be reordered. reorderPoint = 20 A string records the letters A - L. One letter is used to identify a part in the factory. partIds = 'ABCDEFGHIJKL An un-nested list records the stock level of each part. The stock level for each part starts with the value recorded in startLevel. For example, stock level for part A should be recorded at the 0-index, stock level for part B should be recorded at the 1-index, etc. Use another un-nested list to store existing product codes. Start the list empty. (2 marks) Question 2 A factory makes products using parts that are identified by letters A to L. Each product is made of at least 3 different parts, and is identified by a product code made up of letters identifying the parts. The letters in a product code is sorted alphabetically. E.g., a product with product code ABBBG is made up of 1 A, 3 B and 1 G parts. (a) Write and develop a function getPartsInCode which has one string parameter: productCode. The function returns a string in this format: nipi n2p2 ... nkpk. Note nipis are separated by space. For example, if product code is ABBBG, then the function returns 1A 3B 16. Note that the letters in the string parameter are in uppercase and are already sorted. You can use collections of only str type for function. This means collection types such as set, list, dict are not allowed. (5 marks) Apply and employ structured programming and write an application to manage the factory. Other than the data specified in Q2(b), you may use collections of any types for other data in your application. However, you should assume that the user input for product code is not sorted alphabetically. (6) Initialise the following program data in your main method (that is, these variables are not global variables): The stock level for each part is 100 at the start of the application. startLevel = 100 The reorder point for each part is 20. Once the stock level is 20 or below, the part should be reordered. reorderPoint = 20 A string records the letters A - L. One letter is used to identify a part in the factory. partIds = 'ABCDEFGHIJKL An un-nested list records the stock level of each part. The stock level for each part starts with the value recorded in startLevel. For example, stock level for part A should be recorded at the 0-index, stock level for part B should be recorded at the 1-index, etc. Use another un-nested list to store existing product codes. Start the list empty. (2 marks)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started