Q. Write a program to read a file Itemnew.csv and search for an item whose itemno is obtained from the user, as the keyboard input.


Answer :-

import csv
itemno = int(input("Enter item number (For searching):- "))
file = open("Itemnew.csv","r", newline = "\n")
data = csv.reader( file , delimiter = "|" )
found = 0
for i in data :
      if int(i [0] ) == itemno :
            print(i)
            found = 1
if found == 0 :
      print("Not Found !!")
file.close()

Output :-

Enter item number (For searching):- 41286
['41286', 'Pathwalla', '999.99', 'Website']

>>>

Enter item number (For searching):- 98745
Not Found !!

>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post