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 :"))
CodePudding user response:
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)
CodePudding user response:
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.
CodePudding user response:
call the function which you declared above
is_multiple(x,y)