A concise Python program that determines whether a user-provided integer is divisible by 5.
- Python 3
- Built-in
input()function - Built-in
print()function - Modulo operator (
%) - Ternary conditional expression
- 🔢 Accepts an integer input from the user
- ✅ Checks divisibility by 5 using the modulo operator
- ⚡ Implements logic in a single, efficient line using a ternary operator
- 📝 Provides a clear "Yes" or "No" response
- Ensure Python 3 is installed on your computer.
- Download or save the code as
Divisibility.py. - Open your terminal or command prompt.
- Run the program:
python Divisibility.pyThe program will prompt you to enter a number. After you input an integer, it will immediately display "Yes" if the number is divisible by 5, or "No" if it is not.
number: 25Yesnumber: 7No- The program reads the user's input and converts it to an integer.
- It calculates the remainder of the number divided by 5 using
number % 5. - If the remainder is 0, the condition is true and it prints "Yes"; otherwise, it prints "No".
⚠️ This script does not include error handling. Entering non-numeric characters will raise aValueError.- 💡 This is an excellent example of how to write compact, readable conditional logic in Python.