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:
.functions
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:

# Function to display numbers from 100 to 1,000 divisible by 5 and 6.
def displayNumbers():
    count = 0  # Counter variable to keep track of 
    #the number of numbers displayed

    for num in range(100, 1001):
        if num % 5 == 0 and num % 6 == 0:
            print(num, end=" ")
            count += 1

            if count % 10 == 0:
                print()  # Print a new line after displaying ten numbers


# Display the numbers
print("Numbers from 100 to 1,000 divisible by 5 and 6:")
displayNumbers()

Executed Output:

Numbers from 100 to 1,000 divisible by 5 and 6:
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.