Multiple of 7 or Ends with 7
Combine two number rules: divisibility by seven or a last digit of seven. A Python beginner lesson on named boolean values and inclusive or conditions.
1# Take number2num = int(input("Enter a number: "))34# Check conditions5is_multiple = num % 7 == 06ends_with_7 = num % 10 == 778if is_multiple or ends_with_7:9 print("Number is multiple of 7 or ends with 7")10else:11 print("Number is neither multiple of 7 nor ends with 7")
Output
Enter a number: 14 Number is multiple of 7 or ends with 7 Enter a number: 17 Number is multiple of 7 or ends with 7 Enter a number: 15 Number is neither multiple of 7 nor ends with 7
In this one
- Store named booleans
- Combine alternatives with or
- Understand negative remainders
How it works
- 1
Read num and calculate both remainder tests.
- 2
Store is_multiple and ends_with_7.
- 3
Print success when either boolean is true.
Edge cases
Does 77 pass?
Does 77 pass?
Yes. Both conditions are true, and or still accepts it.
Does -17 satisfy the ending test?
Does -17 satisfy the ending test?
No. In Python -17 % 10 is 3; this is not a sign-insensitive text check.
What's going on
The program stores two yes-or-no answers before combining them. is_multiple checks remainder seven; ends_with_7 checks remainder ten for the nonnegative decimal case.
or accepts either answer, including when both are true. Thus 14 and 17 both pass for different reasons. Python remainder on negatives follows the divisor's sign, so a negative number's written last digit needs abs before this test.
Does 77 pass? Yes. Both conditions are true, and or still accepts it.
Does -17 satisfy the ending test? No. In Python -17 % 10 is 3; this is not a sign-insensitive text check.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which operator accepts either rule?
Pick an answer to check it.
Question 2
Does 77 pass?
Pick an answer to check it.
Questions people ask
Does 77 pass?
Yes. Both conditions are true, and or still accepts it.
Does -17 satisfy the ending test?
No. In Python -17 % 10 is 3; this is not a sign-insensitive text check.
Which operator accepts either rule?
or.
๐Related Content
- ๐
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- ๐
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- ๐ป
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum