def find_tallest_person(file_name): with open(file_name, 'r') as file: tallest_person = None max_height = 0 for line in file: data = line.strip().split(',') height = int(data[2]) if height > max_height: max_height = height tallest_person = data if tallest_person: print(f'The tallest person is {tallest_person[0]}, age {tallest_person[1]}, height {tallest_person[2]} cm') else: print('No data found') file_name = 'people.txt' find_tallest_person(file_name)
with open(file_name, 'r') as file:
tallest_person = None
max_height = 0
for line in file:
data = line.strip().split(',')
height = int(data[2])
if height > max_height:
max_height = height
tallest_person = data
if tallest_person:
print(f'The tallest person is {tallest_person[0]}, age {tallest_person[1]}, height {tallest_person[2]} cm')
else:
print('No data found')
file_name = 'people.txt'
find_tallest_person(file_name)
Пример содержимого файла "people.txt":
John,30,180Alice,25,175
Michael,35,190
Sarah,28,165
При выполнении данного кода будет найден человек с наибольшим ростом из файла "people.txt" и выведены его данные.