Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python please complete the attached code for PART A and PART B. In PART A , the program should display the records that are

In python please complete the attached code for PART A and PART B. In PART A, the program should display the records that are in the employees.txt file (please find the text file attached). The output of part A should be the following:

Name: Greg Virgo ID: 4587 Dept: Math Name: Jane Doe ID: 4588 Dept: Reading Name: John Doe ID: 4589 Dept: Advertising 

In PART B, the program should allow the user to search the employees.txt file for records matching an employee name entered by the user. Please see the run sample belows:

Sample Run 1: Enter an employee name to search for: Jane Doe name: Jane Doe ID: 4588 Dept: Reading 
Sample Run 2: 
Enter an employee name to search for: Greg Young name: John Doe ID: 4589 Dept: Advertising 
Sample Run 3:
Enter an employee name to search for: Jerry That employee was not found in the file.

--------------------------------------------------------------------------------------------------------------------------

Some of the code is here, but I'm stuck as to what else needs to be filled in. The bold wording is what I had already put

# PART A # This program displays the records that are # in the employees.txt file

#Part A def main(): # Open the employees.txt file. emp_file = open("employees.txt", "r")

# Read the first line from the file, which is # the name field of the first record. name = emp_file.readline()

# If a field was read, continue processing. while name != '': # Read the ID number field. id_num =

# Read the department field. dept =

# Strip the newlines from the fields. name = id_num = dept =

# Display the record. print('Name:', name) print('ID:', id_num) print('Dept:', dept) print()

# Read the name field of the next record.

# Close the file. emp_file.close()

# Call the main function. main()

# PART B # This program allows the user to search the # employees.txt file for records matching a # employee name.

def main(): # Create a bool variable to use as a flag. found = False

# Get the search value. search =

# Open the employee name file. employee_file =

# Read the first record's name field. name = # Strip the from the name. name =

# Read the rest of the file. while #Insert the condition # Read the ID field. ID =

# Strip the from the ID. ID = # Read the dept field. dept =

# Strip the from the dept. dept =

# Determine whether this record matches # the search value. if #insert the condition here # Display the record. print('name:', name) print('ID:', ID) print('Dept:', dept) print() # Set the found flag to True. # Read the next employee name. # Strip the from the name.

# Close the file. employee_file.close()

# If the search value was not found in the file # display a message. if #insert condition here print('That employee was not found in the file.')

# Call the main function. main()

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

=+Where do you want to live and work?

Answered: 1 week ago

Question

=+1 Where are the best places in the world to live (and work)?

Answered: 1 week ago