Python Program to Print All Negative Numbers in a Range

Python Program to Print All Negative Numbers in a Range

In this python program, we discuss writing a python program to print all Negative numbers in a range. and in this program, the 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 = '   ')

Here is the output of this program

Enter the Minimum Number = -80
Enter the Maximum Number = 500

All Negative Numbers from -80 and 500
-80   -79   -78   -77   -76   -75   -74   -73   -72   -71   -70   -69   -68   -67   -66   -65   -64   -63   -62   -61   -60   -59   -58   -57   -56   -55   -54   -53   -52   -51   -50   -49   -48   -47   -46   -45   -44   -43   -42   -41   -40   -39   -38   -37   -36   -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 

Write a 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

and Here is the output of negative numbers in a range or from 1 to n using a while loop.

Enter the Minimum Number = -50
Enter the Maximum Number = 500

All Negative Numbers from -50 and 500
-50   -49   -48   -47   -46   -45   -44   -43   -42   -41   -40   -39   -38   -37   -36   -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   

Leave a Comment

Exit mobile version