In: Computer Science
Make a python code.
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. Write the program as a loop that continues to prompt for two numbers, outputs the maximum, and then goes back and prompts again
Here’s an example of program use
Input the first number: 10
Input the second number: 5
The maximum value is 10
Run again? yes
Input the first number: -10
Input the second number: -5
The maximum value is -5
Run again? no
Function max():
Obtain two numbers as input parameters: max(num1, num2):
if num1 > num2 max_val = num1, else max_val = num2
return max_val
Main Program:
Initialize loop control variable (continue = ‘y’)
While continue == ‘y’
Prompt for first number
Prompt for second number
Call function “max,” sending it the values of the two numbers, capture result in an assignment statement:
max_value = max (n1, n2)
Display the maximum value returned by the function
print(‘Max =’, max_val)
Ask user for if she/he wants to continue (continue = input(‘Go again? y if yes’)
CODE:
def MAX(num1,num2):
if(num1>num2):
max_val=num1
else:
max_val=num2
return max_val
n1=int(input("Input the first number:"))
n2=int(input("Input the second number:"))
max_val=MAX(n1,n2)
print("Max=",max_val)
Continue=input("Go again? y if yes else n if no:")
while Continue!='n':
n1=int(input("Input the first number:"))
n2=int(input("Input the second number:"))
max_val=MAX(n1,n2)
print("Max=",max_val)
Continue=input("Go again? y if yes else n if no:")
OUTPUT:
If you have any doubts please COMMENT....
If you understand the answer please give THUMBS UP....