I took the "Hour of code" and I now understand your question. To those who didn't follow the link, the OP is about a question in a Python quiz. This explains why the original post was missing colons after the function def. We were looking at code copied from an online test, not running Python code.
def hi(a, b):
return a * b
def hello(a, b):
return hi(a, b + 1)
hello(4, 2)
The test presents some code and you select the answer from multiple choices. I got one wrong when they changed from int addition to string addition. The question above has a correct answer of 12 and the OP is asking why the answer isn't 9. I missed that the first time through. I need to pay better attention.
The OP thinks the answer is 9 because he/she treated function calls like a math equation.
4 * 2 + 1 = 9
9 is the correct answer if you unwind the function calls like they are an equation and use operator precedence.
The correct answer is:
4 * (2 + 1) = 12
12 is the correct answer because Python evaluates arguments before calling the function. When hello(4, 2) calls hi(4, 2+1), the 2+1 is evaluated and replaced with 3.
We can see this if I print out the arguments inside the functions.
def hi(a, b):
print(f'hi({a}, {b})')
return a*b
def hello(a, b):
print(f'hello({a}, {b})')
return hi(a, b+1)
hello(4, 2)
Output:
hello(4, 2)
hi(4, 3)
Inside function hi(a, b), the value for argument b is 3, not 2+1.