1

This is a simple function that checks the values entered by the user and returns true if x is a multiple of y, if not it returns false. When I run the code, it prompts the user to enter a number for x and y but does not display whether it is true or false. What am I doing wrong?

def is_multiple(x, y):
    if (y % x) == 0:
        print("True")
    else:
        print("False")

x = int(input("enter any number :"))
y = int(input("enter a multiple :"))
2
  • 5
    You never call the function. Commented Feb 28, 2022 at 15:44
  • 1
    (Also, your function returns None; it writes the string True or the string False to standard output.) Commented Feb 28, 2022 at 15:49

3 Answers 3

1

You have to call the function after you get the arguments.

def is_multiple(x, y):
    if y % x == 0:
        print("True")
    else:
        print("False")


# Using different names to stress the difference between
# function parameters and function arguments.
n = int(input("enter any number :"))
m = int(input("enter a multiple :"))
is_multiple(n, m)
Sign up to request clarification or add additional context in comments.

Comments

1

As others have mentioned, you have to call the function.

Add this at the end:

is_multiple(x, y)

You could make your function much more useful by doing this however:

def is_multiple(x, y):
if (y % x) == 0:
    return True
else:
    return False

x = int(input("enter any number :"))
y = int(input("enter a multiple :"))
print(is_multiple(x, y))

Now your function actually returns a value that you can use however you'd like. In this case, it is printing the returned value.

Comments

0

call the function which you declared above

is_multiple(x,y)

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.