Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help ASAP for this Python code below The file is not reading to file. It keeps giving me this error message. What am I

Need help ASAP for this Python code below

The file is not reading to file. It keeps giving me this error message. What am I doing wrong?

Importing data from disk..... Traceback (most recent call last): File "F:\Nortey\Fundamentals of Programming Language\Week 5\Final Functionality\Final Functionality.py", line 57, in LoadData() File "F:\Nortey\Fundamentals of Programming Language\Week 5\Final Functionality\Final Functionality.py", line 47, in LoadData line = file.readline() io.UnsupportedOperation: not readable

CODE:

employees = [] count = 0

def Add_Employee(): global count Employee=[] count+=1 print('Enter name of employee:',end='') Employee.append(input()) print('Enter employee SSN:',end='') Employee.append(input()) print('Enter employee phone number:',end='') Employee.append(input()) print('Enter employee email:',end='') Employee.append(input()) print('Enter employee salary:',end='') Employee.append(input()) employees.append(Employee) def view_all_Employees(): for i in employees: print("---------------------------- "+i[0]+" -----------------------------") print('SSN:',i[1]) print('Phone:',i[2]) print('Email:',i[3]) print('Salary:',i[4]) print("NO of employees in the company is",count) print("------------------------------------------------------------------------")

def search_Employee(ssn): for i in range(len (employees)): if(employees[i][1]==ssn): return i return -1

def savedata(): file = open("employees.txt",'w') for employee in employees: file.write("{} {} {} {} {} ".format(employee[0],employee[1],employee[2],employee[3],employee[4])) file.close()

def LoadData(): global count file = open("employees.txt",'w') while True: line = file.readline() data = line.strip(' ').split() if not line or line=='': break else: employees.append(data) count = len(employees)

if __name__ == "__main__": print("Importing data from disk.....") LoadData() print("Data Imported")

while (True): print('Enter -1 to exit') print('Enter 1 to add employee') print('Enter 2 to view all employees') print("Enter 3 to update employee information") print("Enter 4 to search employee with SSN") print("Enter 5 to export employees to file") print("Enter 6 to import employees from file") a = int(input()) if (a == -1): print("Writing to the file.........") savedata() print("Wrote to file now exiting") break elif (a == 1): Add_Employee() print() elif (a == 2): view_all_Employees() print() elif (a == 3): ssn = input("Enter the SSN number to update employee: ") empIndex = search_Employee(ssn) empIndex = search_Employee(ssn) if (empIndex >= 0): employees[empIndex][0] = input("Ente updated name: ") employees[empIndex][2] = input("Enter updated phone number: ") employees[empIndex][3] = input("Enter updated email address: ") employees[empIndex][4] = input("Enter updated salary: ") print("Employee information has been updated successfully. ") else: print("Employee with " + ssn + " is not found. ") elif(a == 4): ssn = input("Enter the SSN number to find employee: ") empIndex = search_Employee(ssn) if (empIndex >= 0): print("---------------------------- " + employees[empIndex][0] + " -----------------------------") print('SSN:', employees[empIndex][1]) print('Phone:', employees[empIndex][2]) print('Email:', employees[empIndex][3]) print('Salary:', employees[empIndex][4]) print("------------------------------------------------------------------------ ") else: print("Employee with " + ssn + " is not found. ")

elif (a == 5): savedata() elif (a == 6): LoadData()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

12-5 How will MIS help my career?

Answered: 1 week ago