Write a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two

Respuesta :

Answer:

The solution code is written in Python

  1. def max(a, b):
  2.    if(a > b):
  3.        return a  
  4.    else:
  5.        return b
  6. num1 = int(input("Please input the first number: "))
  7. num2 = int(input("Please input the second number: "))
  8. print(max(num1, num2))

Explanation:

Firstly create a function max that accepts two input, a and b, as required by question (Line 1). In the function, create if statement to check if a greater than b return a and vice versa (Line 2 -5).

In the main program (Line 7 - 10), prompt user to input two numbers (Line 7 - 8). At last call the function by passing num1 and num2 as arguments and print the result (Line 10).

ACCESS MORE