Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a python code. Write a function named max that accepts two integer values asarguments and returns the value that is the greater of the

Make a python code.

Write a function named max that accepts two integer values asarguments and returns the value that is the greater of the two. Forexample, if 7 and 12 are passed as arguments to the function, thefunction should return 12. Use the function in a program thatprompts the user to enter two integer values. The program shoulddisplay the value that is the greater of the two. Write the programas a loop that continues to prompt for two numbers, outputs themaximum, 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(‘Goagain? y if yes’)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

1 Python Code with proper comments def maxnum1 num2 if num1 num2 if number1 number2 maxva... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Java Programs A Back To Basics Approach

Authors: Stuart Reges, Marty Stepp

5th Edition

013547194X, 978-0135471944

More Books

Students also viewed these Programming questions

Question

How can NAFTA be beneficial to suppliers of Walmart?

Answered: 1 week ago

Question

=+a. At least one plant is completed by the contract date.

Answered: 1 week ago