Table of Contents
Introduction
In previous section we have seen the condition for positive number. Now we will print the positive numbers between the range give.
Program
positive_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 & m <0: print("There is no positive number in the given range") else: # Using for loop for i in range(n,m+1): if i >= 0: positive_list.append(i) print("Positive numbers in the given range {0} and {1} using for loop are {2}".format(n, m, positive_list))
Output
Explanation
In the above python code we have taken the user input range from the user and checked whether the range given are negative or not. If any of the value range is positive integer, the for loop will iterate over the range and append the values greater than 0 to the list. When all the values are traversed the list is displayed on the screen.
0 Comments