Answer the question
In order to leave comments, you need to log in
How to use the value of the variable to get to the name of the employee in another file?
Hello, I want to display the name of the employee who has the highest salary for the first half of the year, but so far I can only display his TIN, since there are two files:
1) contains the name, TIN
2) contains the TIN, salary for the first half of the year, salary for the second half of the year
Here '' print(num[0])'' displays his TIN, tell me how to use this variable to get the name of the employee in another file
def salary():
fileWorkers = open("C:/Users/OWNER/Desktop/lab/workers.txt","r",encoding="utf-8")
infile = open("C:/Users/OWNER/Desktop/lab/salary.txt","r",encoding="utf-8")
arr = []
arr1 = []
arrWor=[]
arrWor_1 = []
max = 0
num = 0
arr = infile.readlines()
for i in arr:
if i and i != "\n":
arr1.append(i.split(","))
for summ in arr1:
if (max<int(summ[1])):
max = int(summ[1])
num=summ
print(num[0])
arrWor = fileWorkers.readlines()
for i in arrWor:
if i and i != "\n":
s = i.split(",")
b = s[1]
if num[0] == b :
print(s[0])
salary()
Answer the question
In order to leave comments, you need to log in
Block with text as a background image with WE, position as needed, min-height according to the height of the image with WE
Briefly, you can:
with open('salary.txt') as file:
lines = file.read().splitlines()
with open('workers.txt') as file:
lines2 = file.read().splitlines()
max_salary = max([x.split(',')[1] for x in lines])
inn = [x.split(',')[0] for x in lines if x.split(',')[1] == max_salary][0]
max_salary_user = [x.split(',')[0] for x in lines2 if x.split(',')[1][4:] == inn][0]
print(max_salary_user)
max_salary = max([x.split(',')[1] for x in lines])
my_list = [] # Создаем пустой список
for x in lines: # перебираем каждую строку
my_list.append(x.split(',')[1]) # Каждую строку делим по запятым, берем второй элемент и добавляем в список.
print(my_list) # В списке будет ['99424', '91300', '91870', '63400', '80500', '68070', '76320', '97600', '98060', '78030']
print(max(my_list)) # С помощью функции max берем сомое большое число из списка.
i = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
for x in i:
if x > 7 and x < 13:
print(x)
i = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
num = [x for x in i if x > 7 and x < 13]
print(num)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question