Предмет: Информатика,
автор: Sokolkaty071115
Программа выводит текст в скобках. Как убрать эти скобки? (Python 3)
fin = open('cities.txt')
outfname = 'squeeze.txt'
with open (outfname,'w') as fout
for line in fin.readlines():
line=line.split()
city=line[0]
country = line[3]
population = float(line[1])
area = float(line[2])
dencity = population/area
if dencity > 10000:
result = city, dencity,country
fout.write(str(result +'n')
fin.close
Приложения:
Ответы
Автор ответа:
0
# Python3
infname, outfname = 'cities.txt', 'squeeze.txt'
with open(infname, 'r') as fin, open(outfname, 'w') as fout:
for line in fin.readlines():
city, population, area, country = line.split()
population, area = map(float, [population, area])
density = population / area
if density > 10000:
fout.write(' '.join(map(str, [city, density, country])) + 'n')
infname, outfname = 'cities.txt', 'squeeze.txt'
with open(infname, 'r') as fin, open(outfname, 'w') as fout:
for line in fin.readlines():
city, population, area, country = line.split()
population, area = map(float, [population, area])
density = population / area
if density > 10000:
fout.write(' '.join(map(str, [city, density, country])) + 'n')
Похожие вопросы
Предмет: Английский язык,
автор: aidarnurgaziev5
Предмет: География,
автор: Аноним
Предмет: Алгебра,
автор: darinaopenko467
Предмет: Математика,
автор: zinovich2017
Предмет: Химия,
автор: gcgxrs