Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

I can use += but why can't I use *= ?

Ok so in the video session numbers the awesome teacher explains how we can use this method that is += , i understood this perfectly but after the video, there is a code challenge that asks me to assign a variable and multiply 365 with that variable. Now when is wrote this *= it gave me an error. Why?

2 Answers

Steven Parker
Steven Parker
243,656 Points

You might have a syntax error.

The operator should work, but perhaps there's something wrong in how you are applying it. It may also be that it doesn't satisfy the requirements as given in the instructions.

Please show your actual code to make an accurate analysis and answer possible. Also please provide a link to the course page you are working with.

Thank you, Steven, for the prompt reply. Ok so here is the link to the code challenge task 2 (https://teamtreehouse.com/library/python-basics/python-data-types/age-calculation) and this is the code I wrote. years = 25 , years *= 365 , days = years

Steven Parker
Steven Parker
243,656 Points

The challenge wasn't expecting the value in "years" to change.

Or more likely, not to end up being the same as "days". But you could do it this way and pass:

years = 25
days = years
days *= 365

But the challenge did specifically ask you to "just multiply years by 365 and assign it to the variable days." So following the instructions exactly would be:

days = years * 365

Your answer will work in real life(without the commas), but I think the answer that is programmed to be accepted is years*365 at this time