41.0k views
1 vote
Write a program that displays, ten numbers per line, all the numbers from100 to 200 that are divisible by 5 or 6, but not both. The numbers areseparated by exactly one space. python

User Sven Tore
by
4.8k points

1 Answer

2 votes

Answer:

So it is really not that hard.

the main idea is to make a simple if loop with an OR statement, it will give us all the required numbers and print them

# the first if statement checks if c is divisible be both 5 and 6 and if they are divisible, it just goes to the next value

#the % divides c by 5 and 6 in each case and gives the remainder, if the remainder is 0, the number is divisible by 5 or 6

# \\ is used to break the current row and go to the next one, by default, every print statement ends with '\\' but since we want 10 numbers a row, we will assign end as a space so that there is a gap between the numbers

Code:

counter = 0

for c in range(100, 201):

if(c%5 == 0 ) and if(c%6 == 0):

if(c%5 == 0) or if(c%6 == 0):

print(c, end = ' ' )

counter += 1

if(counter == 10):

print(\\)

User Mike Perham
by
5.3k points