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.
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
We hope our answers were helpful. Return anytime for more information and answers to any other questions you may have. Thanks for using our service. We're always here to provide accurate and up-to-date answers to all your queries. Thank you for trusting Westonci.ca. Don't forget to revisit us for more accurate and insightful answers.