why does it print 0 and not 5? i cant find the error in my logic?
score = 0
def pass_score(test_string, aScore):
if re.match(a, test_string):
increase_score(5, score)
print (aScore)
def increase_score (aValue, aScore):
aScore += aValue
First approach, without the global var, returning value:
def increase_score (aValue, aScore):
aScore += aValue
return aScore
def pass_score(test_string, aScore):
if re.match(a, test_string):
aScore = increase_score(5, aScore)
print (aScore)
Second approach, using global var:
score = 0
def increase_score (aValue): #don't need to receive score, I've it.
global score
score += aValue
def pass_score(test_string):
global score
if re.match(a, test_string):
increase_score(5)
print (score)
I guess you need a mix of both. Any case, your code looks a bit dirty at this moment, mixing local and global vars.