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.

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
This article has been dead for over six months. Start a new discussion instead.