'Python Zybooks lab function definition input

I have a zybooks lab with the prompt: 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.

My code is:

def max_magnitude(user_val1, user_val2):
   if abs(user_val1) > abs(user_val2):
      return user_val1
   else:
      return user_val2
user_val1 = int(input())
user_val2 = int(input())
print(max_magnitude(user_val1, user_val2))

It works when the input is given as 2 integers, but when the input is something like "max_magnitude(5,8)" then it fails. How can I get the code to work with that form of input?



Solution 1:[1]

def max_magnitude(user_val1, user_val2):
    if abs(int(user_val1)) > abs(int(user_val2)):
      return user_val1
    else:
      return user_val2

if __name__ == '__main__':
    user_val1 = input()
    user_val2 = input()
    print(max_magnitude(user_val1, user_val2))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ALee