Write a function named ​isDivisible​ that takes two parameters
1.maxInt​, an integer
2.twoInts​, a tuple of two integers
The function ​isDivisible​ should create and return a list of all the ints in the range from 1 to ​maxInt(not including ​maxInt​) that are divisible of both ints in ​twoInts​.

b.Create three test cases, each consisting of a value for ​maxInt​ and a value for ​twoInts​, for yourfunction in Problem 2a. One of these tests should return the empty list. For each test casewrite two assignment statements and a function call that pass the test arguments to yourfunction.

Respuesta :

Answer:

def isdivisible():

   maxint=input("Enter the Max Int")

   int1=0

   int2=0

   int1=input("Enter the first Integer")

   int2=input("Enter the second Integer")

   tup1=(int1, int2)

   print(tup1)

   i = 1

   for i in range(1, int(maxint)-1):

       if int(tup1[0])%i==0 & int(tup1[1])%i==0:

           print(i)

       else:

           continue

       

   

isdivisible()    

1.2 Outputs

First test case:

Enter the Max Int6                                                                                                            

Enter the first Integer2                                                                                                      

Enter the second Integer8                                                                                                      

('2', '8')                                                                                                                    

1                                                                                                                              

2      

Second test case: returning empty list

Enter the Max Int2                                                                                                            

Enter the first Integer13                                                                                                      

Enter the second Integer27                                                                                                    

('13', '27')

Test case 3:

Enter the Max Int4                                                                                                            

Enter the first Integer8                                                                                                      

Enter the second Integer10                                                                                                    

('8', '10')                                                                                                                    

1                                                                                                                              

2        

Explanation:

The program is as above, and the three test cases are also mentioned. We have created a tuple out of two input integer, and performed the output as required.

def isDivisible(maxint, twoint):  

        value = []

         for i in range(1, maxint):

                             if i%twoint[0] == 0 and i%twoint[-1] == 0:

                                        value.append(i)

         return value

if __name__ == "__main__":

    assert(isDivisible(15, (4, 5))) == []

    assert(isDivisible(15, (3, 4))) == [12]

     assert(isDivisible(15, (2, 4))) == [4, 8, 12]

print("You passed all the test")

#print(isDivisible(15, (4, 5))

#print(isDivisible(15, (3, 4))

#print(isDivisible(15, (2, 4))

The bolded portion of the code are key words in python.

  • The first line of the code, a function is defined called isDivisible. The function has 2 argument which are integer and a tuple. The tuple only accepts 2 integers value. Tuples unlike arrays are immutable.
  • The second line, a variable called value was declared. The variable was assigned an empty arrays.
  • The third line, a for loop is used to loop through the value from 1 to the first integer argument(excluding the integer itself).
  • The fourth line, there is a check whether the looped values are divisible by the second arguments(tuple that has two integers)
  • The fifth line, if the looped values are divisible by the tuple's 2 integers it will be transferred to the empty array by the function append().
  • Finally, the empty of filled array is returned by the function "return".

The second part(b)of the code :

  • if __name__ == "__main__": is used to execute the code only if the file is run directly and not imported.
  • assert is a keyword in python use for testing. On 3 different occasion, the the code was tested to return an empty list, and 2 filled arrays.

I commented out the last part of the code because it does the same thing as the test case. If we don't want to use if __name__ == "__main__": , then we call the function using the commented part of the code.

Read more: https://brainly.com/question/25267552?referrer=searchResults

Ver imagen vintechnology