हिंदी

Shreyas is a programmer, who has recently been given a task to write a user-defined function named write_bin () to create a binary file called Cust_file.dat containing customer information – customer - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Shreyas is a programmer, who has recently been given a task to write a user-defined function named write_bin () to create a binary file called Cust_file.dat containing customer information – customer number (c_no), name (c_name), quantity (qty), price (price) and amount (amt) of each customer. 

The function accepts customer number, name, quantity and price. Thereafter, it displays the message 'Quantity less than 10.....Cannot SAVE', if the quantity entered is less than 10. Otherwise, the function calculates the amount as price*quantity and then writes the record in the form of a list into the binary file. 

import pickle
def write_bin ():
bin_file = ____________ # Statement 1
while True:
c_no = int (input (“enter customer name”))
c_name = input (“enter customer name”)
qty = int (input ("enter qty"))
price = int (input ("enter price”))
if ________ # Statement2
print (“Quantity less than 10.. Cannot SAVE")
else:
amt = price * gty
c_detail = [c_no, c_name, qty, price, amt]
__________ # Statement 3
ans = input (" Do you wish to enter more records y/n”) if ans. lower () == 'n’:
          __________ # Statement 4
    ____________ # Statement 5
____________#Statement 6

(i) Write the correct statement to open a file 'Cust_file.dat’ for writing the data of the customer.

(ii) Which statement should Shreyas fill in statement 2 to check whether the quantity is less than 10?

(iii) Which statement should Shreyas fill in Statement 3 to write data to the binary file and in Statement 4 to stop further processing if the user does not wish to enter more records?
                                      OR
(iii) What should Shreyas fill in Statement 5 to close the binary file named Cust_file.dat and in Statement 6 to call a function to write data in the binary file?

कोड लेखन
Advertisements

उत्तर

Statement 1: open("Cust_file.dat","wb")
Statement 2: qty<10;
Statement 3: pickle.dump(c_detail,bin_file)
Statement 4: break

OR

Statement 5: bin_file.close()
Statement 6: write_bin() 
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2022-2023 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×