Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python program to count positive and negative numbers in a list

# Python program to count positive and negative numbers in a List
  
# list of numbers
list1 = [-10, -21, -4, -45, -66, 93, 11]
  
pos_count, neg_count = 0, 0
num = 0
  
# using while loop     
while(num < len(list1)):
      
    # checking condition
    if list1[num] >= 0:
        pos_count += 1
    else:
        neg_count += 1
      
    # increment num 
    num += 1
      
print("Positive numbers in the list: ", pos_count)
print("Negative numbers in the list: ", neg_count)
Comment

Python program to print negative numbers in a list

# Python program to print negative Numbers in a List
  
# list of numbers
list1 = [-10, 21, -4, -45, -66, 93]
num = 0
  
# using while loop     
while(num < len(list1)):
      
    # checking condition
    if list1[num] < 0:
        print(list1[num], end = " ")
      
    # increment num 
    num += 1
Comment

Python program to print positive numbers in a list

# Python program to print positive Numbers in a List
  
# list of numbers
list1 = [-10, 21, -4, -45, -66, 93]
num = 0
  
# using while loop     
while(num < len(list1)):
      
    # checking condition
    if list1[num] >= 0:
        print(list1[num], end = " ")
      
    # increment num 
    num += 1
Comment

PREVIOUS NEXT
Code Example
Python :: python read from stdin pipe 
Python :: insert row in dataframe pandas 
Python :: how to check uppercase in python 
Python :: long in python 
Python :: how to join an array of characters in python 
Python :: python save plot 
Python :: python destructure object 
Python :: python insert item into list 
Python :: django 
Python :: how to import matplotlib in python 
Python :: python print() end 
Python :: How to get historical klines python binance 
Python :: python program to reverse a list 
Python :: python if not null 
Python :: nibabel image 
Python :: how list ul li with python scraping 
Python :: modules in python 
Python :: log in python 
Python :: python eliptic curve matplotlib 
Python :: matplotlib object oriented 
Python :: regular expressions in python 
Python :: django add to cart 
Python :: pickle.load from gpu device to cpu 
Python :: how to customize simplejwt error response message in django restframework 
Python :: query set 
Python :: python slice last 2 items of list 
Python :: convert numpy array to tfrecord and back 
Python :: python print main arguments 
Python :: get the first element that is larger than 
Python :: python __add__ 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =