Check Divisible by 5 and 11 in Python
Both remainders 0. 55 yes, 10 no. `and` not `or`.
BeginnerConditional ProgramsExample 5 of 20
check-divisible-by-5-and-11.py
1# Program to check if a number is divisible by both 5 and 1123num = int(input("Enter an integer: "))45if num % 5 == 0 and num % 11 == 0:6 print(num, "is divisible by both 5 and 11")7else:8 print(num, "is not divisible by both 5 and 11")
Output
Enter an integer: 55 55 is divisible by both 5 and 11
In this one
- and, not or
- 55 is the smallest positive example
What's going on
num % 5 == 0 and num % 11 == 0. 55 works. 10 is divisible by 5 and still fails.
or is the bug. 10 would pass. Read the title: both.
LCM of 5 and 11 is 55. That's why 55 is the test case in the output.
After this program
If the idea is still fuzzy, read Day 8: Conditional Statements in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 20 conditional programs, or see every topic on Python exercises.