Computer Science, asked by devishtnayyar30, 9 months ago

Following is the structure of each record in a data file named ”PRODUCT.DAT”. {"prod_code":value, "prod_desc":value, "stock":value} The values for prod_code and prod_desc are strings, and the value for stock is an integer. Write a function in PYTHON to update the file with a new value of stock. The stock and the product_code, whose stock is to be updated, are to be input during the execution of the function.

Answers

Answered by srpappi143
8

Answer:

prod_code=input("Enter product code")

prod_desc=input("Enter product description")

stock=int(input("Enter stock value"))

prod_dct={'prod_code':prod_code, 'prod_desc':prod_desc,'stock':stock}

with file as open("Product.dat"):

file.write('\n')

file.write(prod_dct)

Explanation:

Similar questions