Я посмотрел другой пост об этой же проблеме и не могу найти ответ. Мой код точно такой же, как и в онлайн-классе (оба ниже, но я сократил каталоги). Почему это работает для инструктора, а не для меня?
Ниже мой код:
from matplotlib import pyplot
data = open("lifeexpectanciesusa.txt", "r").readlines()
dates = [ ]
malelife = [ ]
femalelife = [ ]
for line in data:
date, malelife, femalelife = line.split(",")
dates.append(date)
malelife.append(malelife)
femalelife.append(femalelife)
pyplot.plot(dates, malelife,"bo-", label="Men")
pyplot.plot(dates, femalelife, "mo-", label="Female")
pyplot.legend(loc="upper left")
pyplot.xlabel("Year")
pyplot.ylabel("Age")
pyplot.title("Life Expectancies for men and woman in the USA over time")
pyplot.show()
Ниже указано, что инструктор имеет: Код инструктора
Я получаю сообщение об ошибке:
pyplot.show()
Traceback (most recent call last):
File "<ipython-input-56-0283726
068cb>", line 12, in <module>
malelife.append(malelife)
AttributeError: 'str' object has no attribute 'append'