Multiple of 7 or Ends with 7

Check if a number is a multiple of 7 or ends with 7.

IntermediatePhase 1 - Level 3: Math and Number LogicExample 5 of 10
multiple-of-7-or-ends-with-7.py
1# Take number
2num = int(input("Enter a number: "))
3
4# Check conditions
5is_multiple = num % 7 == 0
6ends_with_7 = num % 10 == 7
7
8if 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

What's going on

Use OR operator to check either condition.

Key Concepts:

Multiple of 7: num % 7 == 0
Ends with 7: num % 10 == 7
Use 'or' to check if either is true