0% found this document useful (0 votes)
12 views4 pages

Narveen Sis SQL 2

The document outlines a Python program for creating and searching employee records using the pickle module for data serialization. It includes functions to create employee records by inputting employee number, name, and salary, and to search for records based on employee number. Additionally, it mentions an issue with SQL installation being delayed due to the large file size of the library.

Uploaded by

mdkhalidh18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Narveen Sis SQL 2

The document outlines a Python program for creating and searching employee records using the pickle module for data serialization. It includes functions to create employee records by inputting employee number, name, and salary, and to search for records based on employee number. Additionally, it mentions an issue with SQL installation being delayed due to the large file size of the library.

Uploaded by

mdkhalidh18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

(to create employee record)

import pickle

def create_records():

with open("employees.dat", "ab") as file:

while True:

emp_no = int(input("Enter Employee Number: "))

emp_name = input("Enter Employee Name: ")

emp_salary = float(input("Enter Employee Salary: "))

record = (emp_no, emp_name, emp_salary) # Use a tuple for


simplicity

pickle.dump(record, file) # Save the record to the binary file

if input("Add another record? (y/n): ").lower() != 'y':

break

(to search for an employee record)

def search_record():

emp_no = int(input("Enter Employee Number to search: "))

found = False

try:

with open("employees.dat", "rb") as file:

while True:

try:

record = pickle.load(file)

if record[0] == emp_no: # Match employee number

print("\nEmployee Found:")

print(f"Number: {record[0]}")

print(f"Name: {record[1]}")
print(f"Salary: {record[2]}")

found = True

break

except EOFError:

break

except FileNotFoundError:

print("No records found. Please create records first.")

if not found:

print("Employee not found.")

( Main program)

print("1. Create Employee Records")

print("2. Search Employee Record")

choice = input("Enter your choice (1 or 2): ")

if choice == '1':

create_records()

elif choice == '2':

search_record()

else:

print("Invalid choice.")

(this may look lengthier but easy to understand. It is similar to the program u
asked for. So don’t get afraid)

output may will be similar to:


1. Create Employee Records

2. Search Employee Record

Enter your choice (1 or 2): 1

Enter Employee Number: 101

Enter Employee Name: John Doe

Enter Employee Salary: 50000

Add another record? (y/n): y

Enter Employee Number: 102

Enter Employee Name: Jane Smith

Enter Employee Salary: 55000

Add another record? (y/n): n

1. Create Employee Records

2. Search Employee Record

Enter your choice (1 or 2): 2

Enter Employee Number to search: 101

Employee Found:

Number: 101

Name: John Doe

Salary: 50000

I have downloaded SQL but the installation is getting late. The whole library
is of about 10 GB in the 8.0.41 version for 64 bit .

You might also like