
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print Numbers in an Interval using Python
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given the starting and ending range of an interval. We need to print all the numbers in the interval given.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
There are two for loops, first for loop is for getting the numbers in the interval and second loop for the checking whether the number is prime or not.
Now let’s see the implementation.
Example
start = 10 end = 29 for val in range(start, end + 1): # If num is divisible by any number is not prime if val > 1: for n in range(2, val): if (val % n) == 0: break else: print(val)
Output
11 13 17 19 23 29
All variables and functions are declared in the global scope as shown in the figure below.
Conclusion
In this article, we learned about the approach to print numbers in a given interval.
Advertisements