Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a function bigger(a, b) that returns the bigger of two numbers, without using max. What are bigger(7, 12), bigger(20, 3) and bigger(5, 5)?
return ends the function at once.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. If a is greater than b, return a. Otherwise return b. When return runs, the function ends, so no else is needed.
bigger(7, 12) is 12.bigger(20, 3) is 20.bigger(5, 5) is 5. Both are the same, so either one is right.Log in to join the discussion.
Loading…