- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Find all Numbers in a Range which are Perfect Squares and Sum of all Digits in the Number is Less than 10
When it is required to find all numbers in a range where there are perfect square, and sum of digits in the number is less than 10, list comprehension is used.
Below is the demonstration of the same −
Example
lower_limit = int(input(“Enter the lower range: “)) upper_limit = int(input(“Enter the upper range: “)) my_list = [] my_list = [x for x in range(lower_limit,upper_limit+1) if (int(x**0.5))**2==x and sum(list(map(int,str(x))))<10] print(“The result is : “) print(my_list)
Output
Enter the lower range: 5 Enter the upper range: 12 The result is : [9]
Explanation
The lower range and upper range are taken by the user.
An empty list is defined.
The list comprehension is used, to iterate over the lower and upper limits.
The square root of the elements are found.
The elements are summed up.
It is converted to a list.
This is assigned to a variable.
The output is displayed on the console.
- Related Articles
- Program to find sum of two numbers which are less than the target in Python
- Python Program to Find All Numbers which are Odd and Palindromes Between a Range of Numbers
- Program to find the sum of all digits of given number in Python
- Find the sum of all natural numbers that are less than 100 and divisible by 4.
- Recursive program to print all numbers less than N which consist of digits 1 or 3 only in C++
- Program to find number not greater than n where all digits are non-decreasing in python
- The sum of the squares of two numbers is 233 and one of the numbers is 3 less than twice the other number. Find the numbers.
- Program to find nearest number of n where all digits are odd in python
- Write all the numbers less than 100 which are common multiples of 3 and 4.
- Print a number strictly less than a given number such that all its digits are distinct in C++
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Is a number sum of two perfect squares in JavaScript
- Program to find all contiguously increasing numbers in start end range in Python

Advertisements