Python Exercise: Find numbers which are divisible by 7 and multiple of 5 between a range
Python Conditional: Exercise-1 with Solution
Write a Python program to find those numbers which are divisible by 7 and multiples of 5, between 1500 and 2700 (both included).
Pictorial Presentation:
Sample Solution:
Python Code:
# Create an empty list to store numbers that meet the given conditions
nl = []
# Iterate through numbers from 1500 to 2700 (inclusive)
for x in range(1500, 2701):
# Check if the number is divisible by 7 and 5 without any remainder
if (x % 7 == 0) and (x % 5 == 0):
# If the conditions are met, convert the number to a string and append it to the list
nl.append(str(x))
# Join the numbers in the list with a comma and print the result
print(','.join(nl))
Sample Output:
1505,1540,1575,1610,1645,1680,1715,1750,1785,1820,1855,1890,1925,1960,1995,2030,2065,2100,2135,2170,2205,2240, 2275,2310,2345,2380,2415,2450,2485,2520,2555,2590,2625,2660,2695
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Python Conditional Statements and Loops Exercises Home
Next: Write a Python program to convert temperatures to and from celsius, fahrenheit.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/python-conditional-exercise-1.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics