SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Value Returning Functions And Modules
Exercise:
Programming Exercises
Question:3 | ISBN:9780132576376 | Edition: 2

Question

Maximum of Two Values
Write a function named maximum 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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Maximum of Two Values Python Code:

#The function named maximum that accepts two integer 
#values as arguments and returns the value that is 
#the greater of the two.
def maximum(firstNum, secondNum):
    if firstNum > secondNum:
        return firstNum
    else:
        return secondNum

# Prompt and read the input from the user
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))

# Call the method, maximum
bigNum = maximum(num1, num2)

# Displaying the result
print("The greater value between", num1, "and", num2, "is:", bigNum)

Executed Output:


Enter the first number: 50
Enter the second number:100
The greater value between 50 and 100 is: 100

 

0 0

Discussions

Post the discussion to improve the above solution.