132k views
4 votes
def friendly(number, digits):# ADD YOUR CODE HEREreturn None # CHANGE OR REMOVE THIS STATEMENT# Below you will see an if-statement and a few tests. It is REALLY important# that you not delete this if-statement or the tests inside. You may, however,# add more tests to the code below. You can format them however you like.if __name__ == "__main__": # This line is needed for the auto-grader. DO NOT CHANGE IT!# Check the assignment itself to find what the correct outputs should be# for these tests.print('friendly(42325,5) is', friendly(42325,5))print()print('friendly(82736451,8) is', friendly(82736451,8))print()print('friendly(18,2) is', friendly(18,2))print()print('friendly(497,3) is', friendly(497,3))print()# Write your own tests for this function here!print() # prints a blank line

User Ildelian
by
4.3k points

1 Answer

7 votes

Answer:

The following code is written in python programming language:

#define user defined function

def friendly(number, digits):

#set the while loop

while (number > 0):

#set the if condition

if (number % digits != 0):

#condition true return false

return False

digits -= 1

number //= 10

return True

'''Then you can copy code from the question and paste after this code '''

Output:

friendly(42325,5) is True

friendly(82736451,8) is False

friendly(18,2) is True

friendly(497,3) is False

Step-by-step explanation:

Here, we define a user defined function "friendly()" and pass two argument in its parameter "number", "digits".

Then, we set the while loop and pass the condition "number > 0".

Then, we set the if loop and pass the condition "number % digits != 0" then, if the condition is true then it return false.

And you can copy code from the question and paste after the following code.

User BruceBerry
by
5.6k points