Ваша программа должна заменить все вхождения «Нью-Йорк» на «Нью-Йорк», все вхождения «Нью-Джерси» в «Нью-Джерси»Напишите программу, которая запрашивает у пользователя имя файла адресов и имя выходного файла
Например, если ваш файл replace.txt
содержит:
from wikipedia:
NY-NJ-CT Tri-State Area
The NY metropolitan area includes the most populous city in the US
(NY City); counties comprising Long Island and the Mid- and Lower Hudson
Valley in the state of New York.
выход должен быть:.
from wikipedia:
New York-New Jersey-CT Tri-State Area
The New York metropolitan area includes the most populous city in the United
States (New York City); counties comprising Long Island and the Mid- and
Lower Hudson Valley in the state of New York.
Я старался изо всех сил, и вот моя программа
filename = input("Please enter a file name: ")
openfile = open(filename, "r")
readfile = openfile.read()
for i in readfile:
for string in i.replace("NY", "New York"):
Replace = string.replace("NJ", "New Jersey")
print(Replace)
Проблема в том, что она ничего не печатает. ПОЖАЛУЙСТА, ПОМОГИТЕ!
не работает для NJ! – kunjani
ТОЛЬКО заменяет NY! – kunjani
Теперь он работает. Вы проверяли, когда я добавляю edditing anwser. – Marcin