【发布时间】:2021-02-27 04:27:25
【问题描述】:
**确保代码已创建并在任务 1 中运行以导入 city.txt
-
创建并运行代码以重新打开 citys.txt 作为 city_file
-
read() city_file 到一个名为ities的变量中
-
遍历城市中的字符 a.测试 if .isupper(),如果 True 将字符附加到字符串变量:initials c。 Else if (elif) 字符为“\n”,如果为 True,则将“\n”附加到首字母**
-
打印姓名缩写
cities_file = open('cities.txt', 'r')
城市 = 城市文件.read()
首字母 = " "
对于城市中的城市:
如果 city.isupper() == 真:
city += initials
elif city == "\n":
city += initials
打印(首字母)
【问题讨论】:
标签: python if-statement append