Write your first function that gives back an answer.
What to build
A function bigger(a, b), called from the main program.
Requirements
bigger(a, b)returns the larger of its two arguments.- Do not use
max. - Read two numbers and print the result of calling
bigger.
Input
Two lines, each with one whole number.
Output
One number.
Constraints
The numbers are from -1000000 to 1000000, and they may be equal.
Example
Input:
3
9
Output:
9
Why it works
Because the function returns the value, it could be used inside any other calculation, which printing inside it would not allow.
Examples
Example 1 · Input
3 9
Expected output
9
Example 2 · Input
12 5
Expected output
12
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Write the function with def and two parameters.
Hint 2
Use return, and let the main program do the printing.
Solution
Show one correct solution (try it yourself first)
def bigger(a, b):
if a > b:
return a
return b
x = int(input())
y = int(input())
print(bigger(x, y))