Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can help me with this qns using python? Products using parts that are identified by letters A to L. Each product is made of at

Can help me with this qns using python?

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: n1p1 n2p2 nkpk. Note nipis are separated by space. For example, if product code is ABBBG, then the function returns 1A 3B 1G. (This already done) Other than the data specified in(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.

(b) 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. (c) Offer this menu repeatedly until option 0 is selected to end the application:

Menu

1. Add product code

2. List inventory

3. Update inventory

4. Make product

5. Get summarised data

0. Exit

Respond to the menu choices according to the description below. Qn1- Add product code The program reads a product code. Note that as the letters may be unsorted when it is entered and the letters may be in uppercase or lowercase. The program first sorts the product code and then checks whether the code is valid.

A valid code fulfills these criteria: - The code is at least 3 characters in length. - Each character is a letter from A to L. If the code is valid, the program adds it to a list of product codes if the code is not already in the list of product codes. Display the following messages where appropriate: - The product code is invalid - The product code already exists - The product code has been added successfully I already did the 1st one which is this:

product_codes = [] while True: #displaying menu print("Menu 1. Add product code 2. List inventory 3. Update inventory 4. Make product 5. Get summarised data 0. Exit")

#prompt the user to enter the product code pCode = input('Enter new product code: ') if pCode == '0': break #check for the validation of product code if len(pCode) >= 3 : flag = True for ch in pCode: if ch.upper() >= 'A' and ch.upper() <= 'L': flag = True else: flag = False break if flag == True: if pCode in product_codes: print('The product code already exists') else: product_codes.append(pCode) print('The product code has been added successfully') else: print('The product code is invalid ') else: print('The product code is invalid ')

~~

How to write for these below qns? Qn2- List inventory, The stock level for each part is listed. Note that parts that should be reordered are displayed with asterisk. Example run:

Part Stock Level

A 100

B 100

C 100

D 100

E 12 ***

F 100

G 100

H 20 ***

i 100

J 100

K 100

L 100

Legend: *** stock level at or lower than reorder point 20 Qn3- Update inventory. This option allows the stock level of one or more parts to be restocked. The program repeatedly reads part identifier and the amount to add to the stock level for the part, until an empty string is entered for the part identifier. Each update of a part should be recorded in a file, transactions.txt on separate line in this format: restock letter quantityAdded Example run:

Enter part identifier or to end: T

The part identifier is invalid

Enter part identifier or to end: E

Current stock level for E = 12

Enter quantity to add: 0

The quantity is invalid

Enter part identifier or to end: E

Current stock level for E = 12

Enter quantity to add: -2

The quantity is invalid

Enter part identifier or to end: E

Current stock level for E = 12

Enter quantity to add: 60

Updated stock level for E = 72

Enter part identifier or to end: F

Current stock level for F = 100

Enter quantity to add: 10

Updated stock level for F = 110

Enter part identifier or to end:

Content of transaction.txt :

restock E 60

restock F 10 Qn4- Make product, This option allows a product code and a quantity to make to be entered. Again, assume that the letters in product code is unsorted and may be in uppercase or lowercase. You must use the function getPartsInCode in Q2(a). Here is my code for getPartsInCode:

#a) def getPartsInCode(pCode): #initializing the last character to the first one #and count to zero last = pCode[0];count = 0 #iterating over the string and keep the Count for curr in pCode: 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}') pCode = input("Please enter the product code: ") getPartsInCode(pCode)

Display the following messages where appropriate: - Invalid product code y where y is an non-existing product code.

- Invalid quantity x where x is the a quantity to make, if x is zero or negative.

- x product y successfully made where x is the quantity made and y is the product code. The inventory should be updated.

- x product y made at the current inventory level. z outstanding. where x is the quantity made, z is the quantity that cannot be fulfilled, and y is the product code. The inventory should be updated according to the quantity made. If a part is made and/or if there is outstanding product quantity, the details should be recorded in a file, transactions.txt on separate line in this format:

- if the product is made, record in this format: make code quantityMade

- if there is outstanding product quantity, record in this format: outstanding code quantityOutstanding Example runs

Run 1:

Enter product code: ABCD

Invalid product code ABCD Run 2:

Enter product code: ABBB

Enter quantity to make: -2 Invalid quantity -2 Run 3:

Enter product code: ABBB

Enter quantity to make: 2

2 product ABBB successfully made Run 4:

Enter product code: ABBB

Enter quantity to make: 2

Insufficient inventory.

1 product ABBB made at the current inventory level.

1 outstanding. Content of transaction.txt

# add to previous contents

make ABBB 2

make ABBB 1

outstanding ABBB 1

Qn4- Get summarised data, Prompt and read the type of data (0-restock, 1-make, 2-outstanding) the summary is for. Then, open a file transactions.txt with an appropriate file mode, to produce the summarized report, sorted by quantity followed by either by part or product code. Example runs:

Assume the following 12 lines are in transactions.txt:

make ABBB 2

make ABBC 2

make ABBB 1

outstanding ABBB 1

restock E 60

restock F 10

restock A 60

make ABBC 12

make ABBB 2

make ABBB 2

outstanding ABBB 2

restock F 10 Run 1:

0-restock, 1-make, 2-outstanding. Enter choice: 0

Summarised Data for RESTOCK ***

A 60

E 60

F 20 Run 2:

0-restock, 1-make, 2-outstanding. Enter choice: 1

Summarised Data for MAKE ***

ABBC 14

ABBB 7 Run 3:

0-restock, 1-make, 2-outstanding. Enter choice: 2

Summarised Data for OUTSTANDING ***

ABBB 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

e. What do you know about your ethnic background?

Answered: 1 week ago