Write A Python Script To Check Whether A Given Number Is Divisible By 5 Or Not

This article let's learn a python script that checks whether a given number is divisible completely by five or not.  the given number is said to be completely divisible by 5: if 5 divides the number, the remainder should be zero.

Let's use the modulus operator to get the reminder of a number divisible by 5  and then decide if number is completely divisible by 5 or not.

 

 

Write A Python Script To Check Whether A Given Number Is Divisible By 5 Or Not

 


Write A Python Script To Check Whether A Given Number Is Divisible By 5 Or Not

let's take a variable named as number,  as the user to enter a number using the input function call and converted into an integer type.

number = int(input("Enter a Number : "))



Now using the if statement  and modulus operator try to divide the number by 5 and check if reminder is zero.  if the statement is true then print the number is divisible by 5.  use the else block to print the number is not divisible by 5.

if number % 5 == 0:
   print(f"Number : {number} is Divisible By 5")
else:
   print(f"Number : {number} is Not Divisible By 5")




Complete python script
=================================

number = int(input("Enter a Number : "))

if number % 5 == 0:
   print(f"Number : {number} is Divisible By 5")
else:
   print(f"Number : {number} is Not Divisible By 5")




Output
==============
Enter a Number : 23
Number : 23 is Not Divisible By 5



Output
==============
Enter a Number : 12345
Number : 12345 is Divisible By 5



Output
==============
Enter a Number : 35
Number : 35 is Divisible By 5


Output
=================
Enter a Number : 900
Number : 900 is Divisible By 5




Conclusion
=====================
Execute the above python script by providing Random numbers as input and note down the results.

If the problem statement changes to check for divisibility by 6. You can also modify the number 5 present in the program to check if the number is divisible by any other number for example 6.

Write A Python Script To Check Whether A Given Number Is Divisible By 6 Or Not
====================================
number = int(input("Enter a Number : "))

if number % 6 == 0:
   print(f"Number : {number} is Divisible By 6")
else:
   print(f"Number : {number} is Not Divisible By 6")



Comment it down below if you have any suggestions day improve the above Python program




Post a Comment

0 Comments