Python Forum
max_minus_min_abs - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: max_minus_min_abs (/thread-40752.html)



max_minus_min_abs - whatdoyoumeanitwontpassthru - Sep-17-2023

I have to come up with a code for max_minus_min_abs but I am confused on where to enter the numbers I am passing through. This is what I am using

import math
 
def max_minus_min_abs(first_num, second_num):
    return max(first_num, second_num) - min(first_num, second_num)
    print(max_minus_min_abs(15, 4))



RE: max_minus_min_abs - Pedroski55 - Sep-18-2023

You don't seem to need to import math, unless you are doing something else as well.

def max_minus_min_abs(first_num, second_num):
    return max(first_num, second_num) - min(first_num, second_num)

# split returns a list of strings here
nums = input('Enter 2 numbers separated by a space. ').split(' ')
# use int() to make an integer from the string
result = max_minus_min_abs(int(nums[0]), int(nums[1])
print(f'the difference between {nums[0]} and {nums[1]} is', result)



RE: max_minus_min_abs - deanhystad - Sep-18-2023

Like this:
import math
  
def max_minus_min_abs(first_num, second_num):
    return max(first_num, second_num) - min(first_num, second_num)

print(max_minus_min_abs(15, 4))
Indentation is used to block code in Python. The indenting in your code made the print statement part of the max_minus_min_abs function.


RE: max_minus_min_abs - ICanIBB - Sep-21-2023

def max_minus_min_abs(first_num, second_num):
    return max(first_num, second_num) - min(first_num, second_num)
 
# split returns a list of strings here
nums = input('Enter 2 numbers separated by a space. ').split(' ')
# use int() to make an integer from the string
result = max_minus_min_abs(int(nums[0]), int(nums[1]))
print(f'the difference between {nums[0]} and {nums[1]} is', result)