Program to print negative numbers in the range using Python

by | Mar 29, 2021 | Python Programs

Home » Python » Python Programs » Program to print negative numbers in the range using Python

Introduction

In this section of python programming, we will understand the code to print negative numbers between the given range. The condition of a negative number is that the number should be less than 0.

Program to print negative numbers in the range

Program

negative_list = []
n = int(input("Enter the lower bound of the list "))
m = int(input("Enter the upper bound of the list "))
# Check range
if n>0 and m>0:
    print("There is no negative numbers in the given range")
else:
    for i in range(n, m+1):
        if i < 0:
            negative_list.append(i)
    print("Negative numbers in the given range {0} and {1} using for loop are {2}".format(n, m, negative_list))

Output

Program to print negative numbers in the range Output

Explanation

In the above python code we have taken the range from the user and checked whether the start and end both are positive integers. If any of the range value is negative then, the negative numbers in the range given are appended in the list and displayed on the screen.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author