Question: Python Program : Having some problems with my code. The objective is to take input from the user, and output the name and salary of

Python Program : Having some problems with my code. The objective is to take input from the user, and output the name and salary of any person whose town matches a substring of the input.

For example the user inputs "Louis" then that matches Louisville, Louisberg, and StLouis. If they input "ville" then that would match all employees in Shelbyville, Louisville. In file1 the names are in the format "Firstname Lastname | City.

The program then takes the names of the people in those cities in the first file then searches the 2nd file with them and finds each person and their salary and prints it out. The 2nd files format is a list "Firstname Lastname | Salary ". Below is my code for the program. Im not exactly sure the best way to search the 2nd file with the list of names from the first.

Output shall be one person/salary per line separated by ":" (colon).

Python Program : Having some problems with my code. The objective is

def find( substr, infile): name_list = [] with open(infile) as a: for line in a: if substr in line: name_list.append(line.split('|', 1)[0]) return name_list def find_salaries (substr, infile): mylist = substr with open(infile) as b: for line in b: for i in mylist: for i in line: print(line) sub = raw_input("Please Enter City ") name_list = find (sub, 'file1.txt') find_salaries (name_list, 'file2.txt')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!