Computer Science, asked by amirthavarshini25200, 5 months ago

2. Write a program to enter the following records in a binary file:
Item_No integer
Item_Name string
Qty
integer
Price
float
Number of records to be entered should be accepted from the user.
Read the file to display the records in the following format:
Item No:
Item Name :
Quantity:
Price per item:
Amount:
( to be calculated as Price * Qty)​

Answers

Answered by poojan
6

Language used: Python Programming

Program:

#Entering the records accepted from the user, into a binary file

filee = open("item.dat","ab")

items=[]

no_of_items=int(input())

for i in range(no_of_items):

   Item_No = int(input())

   Item_Name = input()

   Qty = int(input())

   Price = float(input())

   items.append([Item_No, Item_Name, Qty, Price])

pickle.dump(items, filee)

filee.close()

#Reading the data from the binary file

f = open("item.dat","rb")

data= pickle.load(f)

for record in data:

   print("Item No: ",record[0])

   print("Item Name: ",record[1])

   print("Quantity: ",record[2])

   print("Price per item: ",record[3])

   print("Amount: ", record[2]*record[3])

f.close()

Learn more:

Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l.

brainly.in/question/15473120

Python program to find absolute difference between the odd and even numbers in the inputted number.

brainly.in/question/11611140

Similar questions