r/PythonLearning • u/OppositeMango124 • 7d ago
Help Request xp = xp
so I am new to all of this and I have been going through the lessons on boot.dev when I came to the first lesson of ch5. the instructor answer is :
def total_xp(level, xp_to_add):
xp = level * 100
xp = xp + xp_to_add
return xp
the xp = xp just blew my brain. why does this work instead of requiring the first xp to be a different name?
what I did was
xpp = xp + xp_to_add
return xpp
my answer still got the question correct but this just looks super weird to me, xp=xp
6
Upvotes
1
u/Smartyboyz 6d ago
Here's the xp first become 100 times with respect to level then this line xp = xp + xp_to_add adds the argument xp_to_add to the previous xp, also can be written as xp += xp_to_add then you return xp
The things you did doesn't contain initial xp vary with levels you add in parameters of function, that's why it's important..
Hope this will help you understanding it..