Welcome to Westonci.ca, the place where your questions find answers from a community of knowledgeable experts. Get immediate and reliable solutions to your questions from a knowledgeable community of professionals on our platform. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.
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
Thank you for choosing our service. We're dedicated to providing the best answers for all your questions. Visit us again. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Thank you for visiting Westonci.ca, your go-to source for reliable answers. Come back soon for more expert insights.