Why do we do '+='?


#1




Nothing is going wrong, im just wondering why in the example they use '+=' when doing

def finish_game(score):
tickets = 10 * score
if score >= 10:
tickets += 50
elif score >= 7:
tickets += 20
return tickets


Can anyone explain?


#2

it simply means add the value of right hand side variable to the left hand side variable and store the value to the left hand side variable.
for example:

x += y is shorthand for x = x + y

so in your code if the score(parameter) is 20

then it'll return 250

tickets = 10 * 250
tickets += 50 is equivalent to tickets = tickets+50
so tickets=200+50


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.