In: Computer Science
Given a list of negative integers, write a Python program to display each integer in the list that is evenly divisible by either 5 or 7. Also, print how many of those integers were found.
Sample input/output:
Enter a negative integer (0 or positive to end): 5 Number of integers evenly divisible by either 5 or 7: 0
Sample input/output:
Enter a negative integer (0 or positive to end): -5 -5 is evenly divisible by either 5 or 7. Enter a negative integer (0 or positive to end): -35 -35 is evenly divisible by either 5 or 7. Enter a negative integer (0 or positive to end): -3 Enter a negative integer (0 or positive to end): -7 -7 is evenly divisible by either 5 or 7. Enter a negative integer (0 or positive to end): 0 Number of integers evenly divisible by either 5 or 7: 3
# Initializing count to zero count = 0 # reading value of n from user n = int(input("Enter a negative integer (0 or positive to end): ")) # Loop till n becomes zero while(n!=0): # Checking n is divisible by 5 or 7 if (n%5==0) or (n%7==0): # Incrementing count by 1 count += 1 # Printing message print(n,"is evenly divisible by either 5 or 7.") # reading value of n from user again n = int(input("Enter a negative integer (0 or positive to end): ")) # Printing Number of integers evenly divisible by either 5 or 7 print("Number of integers evenly divisible by either 5 or 7:",count)