PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def max(x, y):
if x >=y:
return x
else:
return y
print(max(4, 7))
z = max(8, 5)
print(z)
"""I'm a newbie to Python, but I'll try and explain it as best as I can (with numbers to denote lines of code):
"""
"""Line 1 is defining the function (called 'max') with two arguments in brackets ('x' and 'y').
Line 2 is saying that if the value of x is greater than, or equal to, the value of y, then print - or return, in this case - that value.
As we can see from Line 7, the value of x is '4' and the value of y is '7'. The number '4' is not greater, or equal, to the value of '7' so, according to Lines 4 and 5, a value of 7 will be printed (or 'returned').
Therefore, the first Line in the output will be '7'.
Where does the '8' on the second line come from?
Look to Line 8; a new variable, 'z', is created which uses the function created in Line 1. Inside the parentheses, the value of x is '8' and the value of y is '5'. Now, go back to Lines 2-5 and use the same rules as before.
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run