Python Exercise: Find numbers between two numbers where each digit of a number is an even number
Python Conditional: Exercise - 16 with Solution
Write a Python program to find numbers between 100 and 400 (both included) where each digit of a number is an even number. The numbers obtained should be printed in a comma-separated sequence.
# Create an empty list named 'items' items =  # Iterate through numbers from 100 to 400 (inclusive) using the range function for i in range(100, 401): # Convert the current number 'i' to a string and store it in the variable 's' s = str(i) # Check if each digit in the current number 'i' is even (divisible by 2) if (int(s) % 2 == 0) and (int(s) % 2 == 0) and (int(s) % 2 == 0): # If all digits are even, append the string representation of 'i' to the 'items' list items.append(s) # Join the elements in the 'items' list separated by ',' and print the result print(",".join(items))
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join