**Ensure the code was created and run in Task 1 to import cities.txt
-
Create and run code to re-open cities.txt as cities_file
-
read() cities_file into a variable called cities
-
Iterate through the characters in cities a. Test if .isupper(), if True append the character to a string variable: initials c. Else if (elif) character is "\n", if True append the "\n" to initials**
-
Print initials
cities_file = open('cities.txt', 'r')
cities = cities_file.read()
initials = " "
for city in cities:
if city.isupper() == True:
city += initials
elif city == "\n":
city += initials
print(initials)
Aucun commentaire:
Enregistrer un commentaire