please use python and explain how to solve this question.
Develop a programm that determines if an integer is divisible by 2 and by 3, divisible by 2 or by 3, or is not divisible by neither 2 nor 3.
– The algorithm, isDivisible, analyses the integer and returns an integer that indicates the analysis result: 1 (divisible by 2 and by 3), 2 (divisible by 2 or by 3), 0 (not divisible by neither 2 nor by 3).
– Convert your votre algorithm in Python.
– The program must ask the user for an integer, derive the above value and print the result.
– The program must ask the user for an integer, derive the above value and print the result.
Screenshot of the Code used:
The Output Obtained:
The Code Used:
def isDivisible(check): if check % 2 == 0 and check % 3 == 0: # checking if the number is divisible by both 2 and 3, example 6 or 12. return 1 elif check % 2 == 0 or check % 3 == 0: # checking if the number is divisible by 2 or 3, example 4 or 9 return 2 else: # if the number is not divisible by either 2 and 3, example 7,5,11 etc. return 0 number = int(input("Enter an integer: ")) # asking the user to enter an integer number converting it to integer. print(isDivisible(number)) # calling the isDivisible method and printing the result returned.
I hope you like the solution. In case of any doubts regarding the solution feel free to ask it in the comment section. If you like the solution please give a thumbs up.
Get Answers For Free
Most questions answered within 1 hours.