Design a function named max that accepts two integer values as arguments and returns the value that is greater?

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 greater of the two.

Recommended Answers

All 15 Replies

Which part of that assignment are you having trouble with?

Jason Edgel
Program of max values
#Jason Edgel
#Program of max values

def function_max(value1,value2)
if value1 > value2 then
    return value1
    else
return value2

print "Please enter to integar value:"

value1 = input("Please enter to integar value:")
print "input =", value1
value2 = input("Please enter to integar value:")
print "input =", value2

I can't get the spacing correct, at the very beginning after I define (value1,value2) it shows a syntax error, with red for the space there, I have tried erasing then hitting enter below, no dice...:@

The body of a function definition needs to be indented.

The "then" keyword does not exist in Python and the "else" keyword must be indented at the same level as the corresponding "if". The body of the else clause must also be indented, just like the body of the if.

You're also missing colons everywhere.

#Jason Edgel
#Program of max values
def function_max(value1,value2)
    if value1 > value2 then:
    return value1
    else
return value2

print "Please enter to integar value:"

value1 = input("Please enter to integar value:")
print "input =", value1
value2 = input("Please enter to integar value:")
print "input =", value2

added colon and fixed some indenting, still has the problem right at the top after value... there is nothing there so I dont know why it's red.

Once you learn which statement blocks belong together, then indentation makes more sense. Just think about it. It's all rather logical:

# Jason Edgel
# Program to find max value

def function_max(value1, value2):
    if value1 > value2:
        return value1
    else:
        return value2


# get the two integer values
value1 = input("Please enter first integer value: ")
value2 = input("Please enter second integer value: ")

# call the function
max_value = function_max(value1, value2)

# show the result
print "Max value = ", max_value
###########################################################
# Python program that would display larger of two numbers #
###########################################################


def Max(arg1,arg2):

    if arg1 > arg2: 
        return arg1

    else:
        return arg2



print "Enter first number:",
a = int (raw_input("> "))

print "Enter second number:",
b = int (raw_input("> "))

Max_value = Max(a,b)

print "The greater of the two is:", Max_value

in case the numbers entered are floating points:

###########################################################
# Python program that would display larger of two numbers #
###########################################################


def Max(arg1,arg2):

    if arg1 > arg2: 
        return arg1

    else:
        return arg2



print "Enter first number:",
a = float (raw_input("> "))

print "Enter second number:",
b = float (raw_input("> "))

Max_value = Max(a,b)

print "The greater of the two is:",  Max_value

need help with Pseudocode for design 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. I have the program code I am having trouble with the Pseudocode

Exactly what trouble are you having? What help do you need?
You say you have the code. Did you write it or is it just something random that you found on the web?
If you have good code, then the pseudo code is just an explanation of that code in a simpler, more English, form.

I am having trouble formatting it the proper way, I am new to python so I am still learning

for some reason it will not allow me to post my code

commented: Then make a new discussion about that. Don't bury your posts under old posts. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.