Write a Python program to count the number of even and odd numbers from a series of numbers


Introduction

Write a Python program to count the number of even and odd numbers from a series of numbers. I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) # Declaring the tuple
  2. count_odd = 0
  3. count_even = 0
  4. for x in numbers:
  5. if not x % 2:
  6. count_even+=1
  7. else:
  8. count_odd+=1
  9. print("Number of even numbers :",count_even)
  10. print("Number of odd numbers :",count_odd)

Result

python language techstudy.org

     





Related Topics




Popular Posts