Why I get AttributeError: 'float' object has no attribute '3f'? I am getting this error:

AttributeError: 'float' object has no attribute '3f'


I don't understand why I am getting it, I am following the example straight from the book "applied text analysis"

The chunk of code in python is:

total = sum(words.values())
for gender, count in words.items():
pcent = (count / total) * 100
nsents = sents[gender]
print(
"{0.3f}% {} ({} sentences)".format(pcent, gender, nsents)
)


I see that pcent clearly will return a float, why the author tries to apply .3f what  am I missing?
Try this instead,

  print(
"{:.3f}% {} ({} sentences)".format(pcent, gender, nsents)
)


Refer the latest docs for more examples and check the Py version!