(Find numbers divisible by 5 or 6, but not both) Write a program that displays, ten numbers per line, all the numbers from 100 to 200 that are divisible by 5 or 6, but not both. The numbers are separated by exactly one space.
Find numbers divisible by 5 or 6, but not both Program code:
# Initialize variables
count = 0 # Keeps track of the number of valid numbers found
#Prompt output statement
print("Print ten numbers per line, all the numbers from 100 to 200 that are divisible by 5 or 6, but not both is as:\n")
# Iterate from 100 to 200 (inclusive)
for num in range(100, 201):
# Check if the number is divisible by 5 or 6, but not both
if (num % 5 == 0 or num % 6 == 0) and not (num % 5 == 0 and num % 6 == 0):
# Print the number with a space
print(num, end=" ")
count += 1 # Increment the count
# Check if ten numbers have been printed
if count % 10 == 0:
print() # Print a new line after every ten numbers
# Print a new line if the last line doesn't have ten numbers
if count % 10 != 0:
print()
Executed Output:
Print ten numbers per line, all the numbers from 100 to 200 that are divisible by 5 or 6, but not both is as:
100 102 105 108 110 114 115 125 126 130
132 135 138 140 144 145 155 156 160 162
165 168 170 174 175 185 186 190 192 195
198 200