11.19 LAB: Max magnitude 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. Ex: If the inputs are: 5 7 the function returns: 7 Ex: If the inputs are: -8 -2 the function returns: -8 Note: The function does not just return the largest value, which for -8 -2 would be -2. Though not necessary, you may use the built-in absolute value function to determine the max magnitude, but you must still output the input number (Ex: Output -8, not 8). Your program must define and call the following function: def max_magnitude(user_val1, user_val2)

Respuesta :

Answer:

# the user is prompt to enter first value

user_val1 = int(input("Enter first value: "))

# the user is prompt to enter second value

user_val2 = int(input("Enter second value: "))

# max_magnitude function is defined

# it takes two parameters

def max_magnitude(user_val1, user_val2):

# if statement to compare the values

# it compare the absolute value of each

if(abs(user_val2) > abs(user_val1)):

return user_val2

elif (abs(user_val1) > abs(user_val2)):

return user_val1

# max_magnitude is called with the

# inputted value as parameter

print(max_magnitude(user_val1, user_val2))

Explanation:

The code is written in Python and well commented. A sample image of program output is attached.

Ver imagen ibnahmadbello
fichoh

The function which returns the maximum magnitude value of the two user inputted values written in python 3 is given below ;

val1 = int(input())

  • #first value given by the user

val2 = int(input())

  • #second value given by user

def max_magnitude(user_val1 , user_val2):

  • #max_magnitude function initialized with two arguments which are the user supplied values.

maximum = val1

  • #first value is initially set as the maximum value.

if abs(val1)>abs(val2):

  • #checks which is greater between the absolute values of the two numbers .

maximum = val1

  • # if it's first value is greater, then assign as the maximum

else:

maximum = val2

  • # if otherwise, set the 2nd input as maximum

return maximum

  • # return the maximum value.

print(max(user_val1, user_val2))

Learn more :https://brainly.com/question/15565936

Ver imagen fichoh