SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.loops
Exercise:
Programming Excercises
Question:12 | ISBN:978013274719 | Edition: 6

Question

(Find numbers divisible by 5 and 6) Write a program that displays, ten numbers per line, all the numbers from 100 to 1,000 that are divisible by 5 and 6. The numbers are separated by exactly one space.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Find numbers divisible by 5 and 6 program code:

# Initialize a counter for the number of divisible numbers
count = 0

# Iterate over the range from 100 to 1000 (inclusive)
for number in range(100, 1001):
    # Check if the number is divisible by both 5 and 6
    if number % 5 == 0 and number % 6 == 0:
        # Print the number followed by a space
        print(number, end=" ")
        count += 1

        # Check if ten numbers have been printed in the current line
        if count % 10 == 0:
            # Print a new line
            print()

# Print a final new line if the last line is not complete
if count % 10 != 0:
    print()

Executed Output:

120 150 180 210 240 270 300 330 360 390 
420 450 480 510 540 570 600 630 660 690 
720 750 780 810 840 870 900 930 960 990 

 

 

 

0 0

Discussions

Post the discussion to improve the above solution.