Reputation:
This is my code:
age = 11
days = age*52*7
decades = age/10
estimate = round(decades)
summary = "I am " + {} + " days old! Thats about " {} " decades!".format(str(estimate), str(decades))
Where is the syntax error?
Upvotes: 0
Views: 109
Reputation: 50610
Your format
line is incorrect.
summary = "I am {} days old! Thats about {} decades!".format(estimate, decades)
Unlike other answers, notice that I also removed the str
from your format
tuple. It is not needed.
You may wish to look at output message as well. It currently outputs I am 1.0 days old! Thats about 1 decades!
. At last check, a decade is more than 1 day.
This error is occurring because of this line:
estimate = round(decades)
Your estimate
uses the decades
variable, instead of your days
variable
Upvotes: 2
Reputation: 2012
You're using format
incorrectly. It should be like this:
summary = "I am {0} days old! Thats about {1} decades!".format(str(estimate), str(decades))
Upvotes: 1
Reputation: 6451
You are using the format syntax incorrectly. The curly brackets go inside your string, so:
summary = "I am {} days old! Thats about {} decades!".format(str(estimate), str(decades))
Upvotes: 6