Functions and many return parameters
Programe is:
#
# functions and many return parameters
#
def function_1(a,b):
return a+b
def function_2(a,b):
suma = a + b
if a > b:
minimum =b
else:
minimum = a
return suma, minimum
def function_3(a,b):
suma = a + b
if a > b:
minimum = b
else:
minimum = a
if a > b:
maximum = a
else:
maximum = b
return suma, minimum, maximum
X = 10
Y = 20
Z = function_1(X,Y)
W, V = function_2(X,Y)
A, B, C = function_3(X,Y)
print(' If a=', X, 'and b= ', Y, 'than a+b=', Z)
print(' If a=', X, 'and b= ', Y, 'than a+b=', W, 'minumum is', V )
print(' If a=', X, 'and b= ', Y, 'than a+b=', A, 'minumum is', B,
'and maximum is', C)
Results are:
============== RESTART: /Users/ionivan/Documents/FunctionReturn.py =============
If a= 10 and b= 20 than a+b= 30
If a= 10 and b= 20 than a+b= 30 minumum is 10
If a= 10 and b= 20 than a+b= 30 minumum is 10 and maximum is 20
(April 02, 2022)
#
# functions and many return parameters
#
def function_1(a,b):
return a+b
def function_2(a,b):
suma = a + b
if a > b:
minimum =b
else:
minimum = a
return suma, minimum
def function_3(a,b):
suma = a + b
if a > b:
minimum = b
else:
minimum = a
if a > b:
maximum = a
else:
maximum = b
return suma, minimum, maximum
X = 10
Y = 20
Z = function_1(X,Y)
W, V = function_2(X,Y)
A, B, C = function_3(X,Y)
print(' If a=', X, 'and b= ', Y, 'than a+b=', Z)
print(' If a=', X, 'and b= ', Y, 'than a+b=', W, 'minumum is', V )
print(' If a=', X, 'and b= ', Y, 'than a+b=', A, 'minumum is', B,
'and maximum is', C)
Results are:
============== RESTART: /Users/ionivan/Documents/FunctionReturn.py =============
If a= 10 and b= 20 than a+b= 30
If a= 10 and b= 20 than a+b= 30 minumum is 10
If a= 10 and b= 20 than a+b= 30 minumum is 10 and maximum is 20
(April 02, 2022)
Comments
Post a Comment