As per the question, the user-defined function should accept two numbers and then compare them before returning the values. Therefore, ‘if’ statement can be used inside the user-defined function to compare and return the values.
Program:
#defining a function to swap the numbers
def swapN(a, b):
if(a < b):
return b,a
else:
return a,b
#asking the user to provide two numbers
n1 = int(input("Enter Number 1: "))
n2 = int(input("Enter Number 2: "))
print("Returned value from function:")
#calling the function to get the returned value
n1, n2 = swapN(n1, n2)
print("Number 1:",n1," Number 2: ",n2)
OUTPUT:
Enter Number 1: 3
Enter Number 2: 4
Returned value from function:
Number 1: 4 Number 2: 3