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 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 :: transition from python 2 to 3 terminal 
Python :: django model form 
Python :: model evaluate function 
Python :: selenium element_to_be_clickable PYTHON 
Python :: python variable declare 
Python :: fibonacci series using recursion in python 
Python :: numpy divide with exception 
Python :: factors for negative number python 
Python :: python array slice 
Python :: django admin 
Python :: get tweet by its id 
Python :: python compare sets 
Python :: python pop 
Python :: python snake case to camel case 
Python :: Iniciar servidor en Django 
Python :: pairplot with selected field 
Python :: play music pygame 
Python :: opencv convert black pixels to white 
Python :: load pt file 
Python :: pickle load data 
Python :: ffmpeg python video from images 
Python :: python red table from pdf 
Python :: reading doc in python 
Python :: # write json file 
Python :: python save to excel 
Python :: python visualize fft of an image 
Python :: remove unnamed columns pandas 
Python :: create dict from two lists 
Python :: get local ipv4 
Python :: get body from request python 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =