Here's the prompt:
Assign max_sum with the greater of num_a and num_b, PLUS the greater of num_y and num_z. Use just one statement. Hint: Call find_max() twice in an expression.
Here's my code:
def find_max(num_1, num_2):
max_val = 0.0
if (num_1 > num_2): # if num1 is greater than num2,
max_val = num_1 # then num1 is the maxVal.
else: # Otherwise,
max_val = num_2 # num2 is the maxVal
return max_val
max_sum = 0.0
num_a = float(input())
num_b = float(input())
num_y = float(input())
num_z = float(input())
def find_max(num_a, num_b):
max_val = 0.0
if (num_a > num_b):
max_val = num_a
else:
max_val = num_b
def find_max(num_y, num_z):
max_val = 0.0
if (num_y > num_z):
max_val = num_y
else:
max_val = num_z
print('max_sum is:', max_sum)
Not sure what I've done wrong. I've tried this also
def find_max(num_a, num_b):
max_1 = 0.0
if (num_a > num_b):
max_1 = num_a
else:
max_1 = num_b
def find_max(num_y, num_z):
max_2 = 0.0
if (num_y > num_z):
max_2 = num_y
else:
max_2 = num_z
max_sum = (max_1 + max_2)
That gives me an error message that "max_1 is not defined" even though I've defined it. The first code just gives me an output of 0.0.
Any tips? Thanks!