In this example we will show how to find numbers within a given range that can be divided by 3 and 5 at the same time.
Source Code
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
lowerLimit = int(input("Please input the lower limit: "))
upperLimit = int(input("Please input the upper limit: "))
print('Bwteen {} and {}, the numbers can be divided by 3 and 5 at the same time are: '.format(lowerLimit, upperLimit))
for i in range(lowerLimit, upperLimit + 1):
if i % 3 == 0 and i % 5 == 0:
print(str(i) + "\t", end=" ")
print()
Output:
Please input the lower limit: 1
Please input the upper limit: 50
Bwteen 1 and 50, the numbers can be divided by 3 and 5 at the same time are:
15 30 45
Please input the lower limit: 100
Please input the upper limit: 200
Bwteen 100 and 200, the numbers can be divided by 3 and 5 at the same time are:
105 120 135 150 165 180 195