Westonci.ca is the ultimate Q&A platform, offering detailed and reliable answers from a knowledgeable community. Get the answers you need quickly and accurately from a dedicated community of experts on our Q&A platform. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.

A common test for divisibility by 3 is to add the individual digits of an integer. If the resulting sum is divisible by 3 then so is the original number. Program this test. To do this, first define a function: reduce(number) which returns the sum of the digits of the number argument. The sum returned must be < 20 i.e. if the sum is >= 20, the function must add the digits of the resulting sum. It should repeat this procedure until the sum is < 20. Use this function in a python program that inputs an integer from the user and prints out whether or not the integer is divisible by 3.​

A Common Test For Divisibility By 3 Is To Add The Individual Digits Of An Integer If The Resulting Sum Is Divisible By 3 Then So Is The Original Number Program class=

Sagot :

The function to test for divisibilty by 3 will accept an input integers and divide it by three to check if its divisible by 3.

The function to test for divisiblity by 3 is as follows:

integer = input("input the integer to check if it's divisible by 3: ")

def reduce(integer):

    list1 = []

    sum1 = 0

    for i in str(integer):

         list1 += i

    results = list(map(int, list1))

    for x in results:

         sum1 += x

    if sum1 < 20 and sum1%3==0:

         return "The integer is divisible by 3"

    elif sum1 < 20 and sum1%3 != 0:

         return "The integer is not divisible by 3"

    else:

         while sum1 >= 20:

              z = sum(list(map(int, list(str(sum1)))))

              if z%3==0:

                   return "The integer is divisible by 3"

              else:

                   return "The integer is not divisible by 3"    

print(reduce(integer))

Code explanation

  • The integer variable stores the users input.
  • We define a function called "reduce". The reduce function accepts the interger variable as a parameter.
  • The code loop through the integer and check if it is divisible by 3.
  • If the sum of the integer number is greater or equals to 20, we divide the resulting sum by 3 .
  • If the integer is divisible by 3, we return "it is divisble by 3" and if it is not dividible by 3, it will return "it is not divisble by 3".

learn more on python here: https://brainly.com/question/13437928