dimanche 15 novembre 2020

How do I get the city output to append itself into initials and then print it?

**Ensure the code was created and run in Task 1 to import cities.txt

  1. Create and run code to re-open cities.txt as cities_file

  2. read() cities_file into a variable called cities

  3. 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**

  4. 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