Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python program to print odd numbers in a List

# Python program to print odd Numbers in a List
  
# list of numbers
list1 = [10, 21, 4, 45, 66, 93]
  
# iterating each number in list
for num in list1:
      
    # checking condition
    if num % 2 != 0:
       print(num, end = " ")
Comment

Python program to count Even and Odd numbers in a List

# Python program to count Even
# and Odd numbers in a List
  
# list of numbers
list1 = [10, 21, 4, 45, 66, 93, 1]
  
even_count, odd_count = 0, 0
  
# iterating each number in list
for num in list1:
      
    # checking condition
    if num % 2 == 0:
        even_count += 1
  
    else:
        odd_count += 1
          
print("Even numbers in the list: ", even_count)
print("Odd numbers in the list: ", odd_count)
Comment

Python program to count Even and Odd numbers using while loop in a List

# Python program to count Even and Odd numbers in a List
  
# list of numbers
list1 = [10, 21, 4, 45, 66, 93, 11]
  
even_count, odd_count = 0, 0
num = 0
  
# using while loop     
while(num < len(list1)):
      
    # checking condition
    if list1[num] % 2 == 0:
        even_count += 1
    else:
        odd_count += 1
      
    # increment num 
    num += 1
      
print("Even numbers in the list: ", even_count)
print("Odd numbers in the list: ", odd_count)
Comment

PREVIOUS NEXT
Code Example
Python :: shutil copyfile python 
Python :: pandas xlsx to dataframe 
Python :: python regex get all matches 
Python :: how to remove stop words in python 
Python :: pandas read first column as index 
Python :: pandas dataframe total row 
Python :: argeparse can it take a type list 
Python :: if string contains list of letters python 
Python :: dataframe get index name 
Python :: serial clear buffer python 
Python :: sum of all multiples of 3 and 5 below 100 
Python :: django urlpattern 
Python :: password generator in python 
Python :: numpy empty image 
Python :: how to pause time in python 
Python :: pandas most frequent value 
Python :: print only numbers from string python 
Python :: tkmessagebox not found 
Python :: api in python 
Python :: lag function in pandas 
Python :: tkinter menus 
Python :: python reverse list complexity 
Python :: python append to first index 
Python :: how to reboot a python script 
Python :: python regex match words 
Python :: replace value pandas df 
Python :: how to count unique values in dataframe df python 
Python :: get only first 10 columns pandas 
Python :: integer colomn to datetime 
Python :: image rotate in python 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =