SIMULATION
Complete the function get_max(a, b) that returns the larger of two numbers. If they are equal, return either one.
def get_max(a, b):
# TODO: Return the larger of a and b
pass
==========
Step 1: The function receives two parameters: a and b.
Step 2: Compare the two values using an if statement.
Step 3: If a is greater than or equal to b, return a.
Step 4: Otherwise, return b.
Correct code:
def get_max(a, b):
if a >= b:
return a
else:
return b
Simplified correct code:
def get_max(a, b):
return max(a, b)
Example:
print(get_max(10, 20))
print(get_max(30, 15))
print(get_max(5, 5))
Output:
20
30
5
Andree
Ivette
5 days agoLayla
10 days agoEmiko
15 days ago