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).
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started