1
Natural data m and n determine, among all pairs of natural numbers (x,y) such that x < m and y < n, a pair for which the value of the expression x*y - x**2 + y is maximum and also calculates this maximum.
I solved the problem like this:
m = int(input("Digite m: "))
n = int(input("Digite n: "))
#m = 2
#n =1
x = 0
y = 0
maximo =0
x_maximo = 0
y_maximo = 0
while x <m and y<n:
for i in range(m):
for j in range(n):
soma = i*j -i**2 +j
print (soma)
if soma > maximo:
maximo = soma
x_maximo = i
y_maximo = j
x +=1
y +=1
print ("O máximo é {} para o par (x,y) = ({},{})". format(maximo,x_maximo,y_maximo))
Apparently, the algorithm is correct but I found that the solution is not very elegant. Any suggestions on how to improve it? Some simpler way?
What would be lambda?
– Ed S
@Eds conceptually, the expression lambda "is" an "anonymous" function that transforms an input A into an output B.
– Woss