Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Looping Statements

Display numbers divisible by 7 but not by 5 - Python Program

Example 1 :

# Numbers divisible by 7 but not by 5 start = int(input("Enter start: ")) end = int(input("Enter end: ")) print(f"Numbers divisible by 7 but not by 5 between {start} and {end}:") for num in range(start, end + 1): if num % 7 == 0 and num % 5 != 0: print(num, end=" ")

Output

 
OUTPUT  :
Enter start: 1
Enter end: 50
Numbers divisible by 7 but not by 5 between 1 and 50:
7 14 21 28 42 49
 

Explanation

  • Checks num % 7 == 0 for divisibility by 7.
  • Ensures num % 5 != 0 to exclude multiples of 5.