Python Program to Print Negative Numbers in a Range

Write a Python program to print negative numbers in a range. This Python example allows start and end numbers and prints the negative numbers within that range.

minimum = int(input("Enter the Minimum Number = "))
maximum = int(input("Enter the Maximum Number = "))

print("\nAll Negative Numbers from {0} and {1}".format(minimum, maximum)) 
for num in range(minimum, maximum + 1):
    if num < 0:
        print(num, end = '   ')
Python Program to Print Negative Numbers in a Range

Python program to print negative numbers in a range or from 1 to n using a while loop.

minimum = int(input("Enter the Minimum Number = "))
maximum = int(input("Enter the Maximum Number = "))

print("\nAll Negative Numbers from {0} and {1}".format(minimum, maximum))
while minimum <= maximum:
    if minimum < 0:
        print(minimum, end = '   ')
    minimum = minimum + 1
Enter the Minimum Number = -35
Enter the Maximum Number = 400

All Negative Numbers from -35 and 400
-35   -34   -33   -32   -31   -30   -29   -28   -27   -26   -25   -24   -23   -22   -21   -20   -19   -18   -17   -16   -15   -14   -13   -12   -11   -10   -9   -8   -7   -6   -5   -4   -3   -2   -1  

In this Python example, the negativeNumbers function accepts two integers and prints the negative numbers between them.

def negativeNumbers(x, y):
    for num in range(x, y + 1):
        if num < 0:
            print(num, end = '   ')


minimum = int(input("Enter the Minimum = "))
maximum = int(input("Enter the Maximum = "))

print("\nAll Negative Numbers from {0} and {1}".format(minimum, maximum)) 
negativeNumbers(minimum, maximum)
Enter the Minimum = -25
Enter the Maximum = 120

All Negative Numbers from -25 and 120
-25   -24   -23   -22   -21   -20   -19   -18   -17   -16   -15   -14   -13   -12   -11   -10   -9   -8   -7   -6   -5   -4   -3   -2   -1