Friday, 21 August 2020

Create a binary file with roll number, name and marks. Input a roll number and update the marks.



PROGRAM:

 




OUTPUT:



16 comments:

  1. It's very helpful and good👍👍

    ReplyDelete
  2. Thanks a lot... You don't know how much you people have helped me❤️❤️

    ReplyDelete
  3. please sir iska sorce code dedo yaha par copy karna hau?

    ReplyDelete
    Replies
    1. import pickle
      student_data={}

      no_of_students=int(input("Enter no of students: "))
      file=open("student0.dat","ab")
      for i in range(no_of_students):
      student_data["RollNo"]=int(input("Enter roll no: "))
      student_data["Name"]=input("Enter Student name: ")
      student_data["Marks"]=float(input("Enter Student Marks: "))
      pickle.dump(student_data,file)
      student_data={}
      file.close()
      file=open("student0.dat","rb")
      try:
      while True:
      student_data=pickle.load(file)
      print(student_data)
      except EOFError:
      file.close()

      found=False
      roll_no=int(input("enter the roll no to search: "))
      file=open("student0.dat","rb+")
      try:
      while True:
      pos=file.tell()
      student_data=pickle.load(file)
      if(student_data["RollNo"])==roll_no:
      student_data["Marks"]=float(input("Enter marks to be updated: "))
      file.seek(pos)
      pickle.dump(student_data,file)
      found=True
      except EOFError:
      if(found==False):
      print("Roll no not found Please Try Again")
      else:
      print("Student marks updated successfully")
      file.close()

      file=open("student0.dat","rb")
      try:
      while True:
      student_data=pickle.load(file)
      print(student_data)
      except EOFError:
      file.close()










      Delete
  4. This helped me understand the logic behind...Thank You!!!

    ReplyDelete
  5. Sirif mai hii hua kya jo practicals complete karne yaha aaya hai?

    ReplyDelete
  6. import pickle
    student_data={}

    no_of_students=int(input("Enter no of students: "))
    file=open("student0.dat","ab")
    for i in range(no_of_students):
    student_data["RollNo"]=int(input("Enter roll no: "))
    student_data["Name"]=input("Enter Student name: ")
    student_data["Marks"]=float(input("Enter Student Marks: "))
    pickle.dump(student_data,file)
    student_data={}
    file.close()
    file=open("student0.dat","rb")
    try:
    while True:
    student_data=pickle.load(file)
    print(student_data)
    except EOFError:
    file.close()

    found=False
    roll_no=int(input("enter the roll no to search: "))
    file=open("student0.dat","rb+")
    try:
    while True:
    pos=file.tell()
    student_data=pickle.load(file)
    if(student_data["RollNo"])==roll_no:
    student_data["Marks"]=float(input("Enter marks to be updated: "))
    file.seek(pos)
    pickle.dump(student_data,file)
    found=True
    except EOFError:
    if(found==False):
    print("Roll no not found Please Try Again")
    else:
    print("Student marks updated successfully")
    file.close()

    file=open("student0.dat","rb")
    try:
    while True:
    student_data=pickle.load(file)
    print(student_data)
    except EOFError:
    file.close()










    ReplyDelete
  7. While running the program I am getting typeerror tuple object does not support item assignment.
    So please can you help me out to run this properly

    ReplyDelete