Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

while loop odd numbers python

# Python Program to Print Odd Numbers from 1 to N

maximum = int(input(" Please Enter the Maximum Value : "))

number = 1

while number <= maximum:
    if(number % 2 != 0):
        print("{0}".format(number))
    number = number + 1
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 :: Sorting a list using a named function 
Python :: python pip past 
Python :: sum of list of numbers 
Python :: ljust rjust center python 
Python :: convert blocks to mb python 
Python :: decision tree algorithm 
Python :: deepcopy python 
Python :: pandas interpolate string 
Python :: append numeric number in and auto increment in using pandas 
Python :: python genap ganjil 
Python :: python can you put try except in list comprehension 
Python :: pascal triangle 
Python :: python odd or even 
Python :: def create(self validated_data) 
Python :: quotation marks n string 
Python :: bar chart in python 
Python :: fastest way to compute pair wise distances python 
Python :: install pytorch on nvidia jetson nx 
Python :: looping through strings 
Python :: avoid bad request django 
Python :: pydub audiosegment to numpy array 
Python :: shared SHMEM python 
Python :: discord embed python 
Python :: pandas print column by index 
Python :: mistborn books 
Python :: fonction nombre premier python 
Python :: create table numpy 
Python :: sleep your computer python 
Python :: flask run development mode 
Python :: keras.datasets no module 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =