66.2k views
5 votes
python Write a function max_magnitude() with two integer input parameters that returns the largest magnitude value. Use the function in a program that takes two integer inputs, and outputs the largest magnitude value.

User Einav
by
5.7k points

1 Answer

1 vote

Answer:

def max_magnitude(num1, num2):

if abs(num1) >= abs(num2):

return num1

else:

return num2

n1 = int(input("Enter the first number: "))

n2 = int(input("Enter the second number: "))

print(max_magnitude(n1, n2))

Step-by-step explanation:

Create a function called max_magnitude that takes two parameters, num1, and num2

Check the numbers magnitude, use abs function to get their absoulute values.

If magnitude of the first one is greater than or equal to the second one, return first one. Otherwise, return second one.

Get the numbers from the user

Call the function with given numbers to see the result

User Leochab
by
5.5k points