Write a program DivisionCheckpy that reads an integer and pr

Write a program DivisionCheck.py that reads an integer and prints whether it is divisible by only 2 or divisible by only 3 or divisible by both or divisible by neither 2 nor 3. Additional Information Use remainder operator Use input function to receive user input Get the user input by displaying the message \"Enter an integer: Assume that user inputs only integers Follow all naming conventions as discussed in the class Variable names should be with underscore. For example, first_name Program name first letter of each word uppercase. For example FindMax.py Expected output Enter an integer: 5 Number 5 is divisible neither by 2 nor by 3 Enter an integer: 12 Number 12 is divisible by both 2 and 3 Enter an integer: 9 Number 9 is divisible by 3 but not 2 Enter an integer: 4 Number 4 is divisible by both 2 but not 3

Solution

input_num = int(input(\"Enter a integer: \"))
if input_num % 2 ==0 and input_num % 3 == 0:
print(\"Number \"+str(input_num)+\" is divisible by both 2 and 3\")
elif input_num % 2 == 0 and input_num % 3 != 0:
print(\"Number \"+str(input_num)+\" is divisible by 2 but not 3\")
elif input_num % 3 == 0 and input_num % 2 != 0:
print(\"Number \"+str(input_num)+\" is divisible by 3 but not 2\")
else:
print(\"Number \"+str(input_num)+\" is divisible by neither by 2 nor by 3\")

Output:

sh-4.3$ python3 main.py                                                                                                                                                                                                                                                

Enter a integer: 5                                                                                                                                                                                                                                                     

Number 5 is divisible by neither by 2 nor by 3                                                                                                                                                                                                                         

sh-4.3$ python3 main.py                                                                                                                                                                                                                                                

Enter a integer: 12                                                                                                                                                                                                                                                    

Number 12 is divisible by both 2 and 3                                                                                                                                                                                                                                 

sh-4.3$ python3 main.py                                                                                                                                                                                                                                                

Enter a integer: 9                                                                                                                                                                                                                                                     

Number 9 is divisible by 3 but not 2                                                                                                                                                                                                                                   

sh-4.3$ python3 main.py                                                                                                                                                                                                                                                

Enter a integer: 4                                                                                                                                                                                                                                                     

Number 4 is divisible by 2 but not 3

 Write a program DivisionCheck.py that reads an integer and prints whether it is divisible by only 2 or divisible by only 3 or divisible by both or divisible by

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site